-2

如何在jquery中使用双qoute参数化函数进行html编码..

我有一个功能

 function ToggleDropDown(id1,id2);
 {
   var e = document.getElementById("" + id1+ "");
   var strUser = e.options[e.selectedIndex].text;
   $("#" + id2 + "").text(strUser);
 }

现在有一个构建数据网格和组合按钮的 jquery ..

 ....
 var control='<div class=...../* other code */>';
 controls += '<select id="GlobalFieldName" onchange=ToggleDropDown("GlobalFieldName","globalSelect");">';

现在在firebug的html源文件中我得到了类似下面的代码..

 <select id="GlobalFieldName" globalfieldname","globalselect");"=""   onchange="ToggleDropDown(">
 ......

我必须在我的函数的参数中设置双 qoute,否则我必须在我不想做的所有其他地方进行更改..任何想法..!!?

4

1 回答 1

1

你可以做这样的事情

controls += '<select id="GlobalFieldName" data-file=\'"GlobalFieldName"\' data-select= \'"globalSelect"\' onchange=ToggleDropDown(this.getAttribute(\"data-file\",\"data-select\");">';
于 2013-09-30T08:29:15.910 回答