开发者

Convert classic asp variable into jquery variable

开发者 https://www.devze.com 2023-04-04 22:40 出处:网络
Here is my code.. This is giving me a hard time though I know there is a simple answer var开发者_StackOverflow社区 myVAr = \'<%=data.name%>\';

Here is my code.. This is giving me a hard time though I know there is a simple answer

var开发者_StackOverflow社区 myVAr = '<%=data.name%>';

$(myVAr).insertAfter("#thisDiv");


You must call insertAfter on a jquery object. So you could do:

var myVAr = $('<input>',{name :'<%=data.name%>', type: "text"} );

myVAr.insertAfter("#thisDiv");

fiddle here http://jsfiddle.net/FhUF5/


Make sure the data.name does not have a ' inside it as it will break the javascript string.

And then make sure that the jquery code is executed after the page has loaded

var myVAr = '<%=data.name%>';
$(function(){
  $(myVAr).insertAfter("#thisDiv");
});

If the data.name does not represent valid html code, and you just want the data.name to be inserted as text after the #thisDiv then make a tag with jquery which holds the data.name

var myVAr = '<%=data.name%>';
$(function(){
  $('<span>',{text:myVAr}).insertAfter("#thisDiv");
});
0

精彩评论

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