开发者

Handling special characters in javascript

开发者 https://www.devze.com 2022-12-22 09:08 出处:网络
In the below code: var id=obj.setid({{info}}); I get an error saying illegal characterand {{info}} has the followingstring:

In the below code:

var id=obj.setid({{info}});

I get an error saying illegal character and {{info}} has the following string:

"Website® is registered "

How do I handle this error in javascript?

Thanks..

Edit:

  setid looks like this
    setid: function (id)
                 {
                    var obj = $(this) ;
开发者_如何学编程                     validate_id(id);
                 },


mystring = "Website® is registered";
alert(mystring);

Works just fine, it has nothing to do with the value of info -- the question is what do you think you're doing with {{info}}?

This is wrong if obj.setid is expecting a string or an object. The correct way would be:

// Wants a string
obj.setid(info);

// Wants an object
obj.setid({'text':info});

Hard to tell without knowing what obj.setid is


Don't you need to put your string in quotes?

var id = obj.setid('{{info}}');

I can't tell from your post whether the "info" string has quotes in it already.


It looks like you're trying to set the id attribute of a DOM element to the value "website is registered", which is not a valid value for an id attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消