且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将响应值分配给变量?

更新时间:2022-10-20 08:24:28

#test)。load( test.aspx?test = +值);

}


< / script >

< / head >
< 正文 >


< 选择 id = combo1 onchange = getCombo1 (this) >
< 选项 value = ka > Karnataka < / option >
< 选项 value = tn > Tamilnadu < / option >
< 选项 value = ap > Andrapradesh < / option >
< 选项 value = mh > Maharashtra < / option >
< / select >

< pre id = test >





< / body>

它将在p tag $中显示输出b $ b但是我希望它显示在这个
< select id =Select1>
< option>< / option>
< / select>


这不完全是组合框;这是HTML 选择元素。通过显示,您可能意味着选择项目(选项元素)取决于您的某些价值



Of当然,你不能在这里使用jQuery .load 。请看它的作用:

https://api.jquery.com/load [ ^ ]。



它在元素中放置了一些HTML。这不是你想要的。您想从一个选项元素中删除选定的属性,并将此属性添加到其他一些(或可能相同)元素,或者没有,如果没有匹配。



这里解释了这些操作的实现;请参阅问题的***答案: http://***.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery [ ^ ]。



而不是 .load ,您需要从服务中提取值。使用通用jQuery Ajax: http://api.jquery.com/jquery.ajax [ ^ ]。



那是所有。正如你所看到的,这比 .load 要复杂得多,但没什么太难的。



-SA

<script type="text/javascript">
    function getCombo1(sel)
  {
        var value = sel.options[sel.selectedIndex].value;
        $("#test").load("test.aspx?test=" + value);
      
    }
    

</script>

</head>
<body>
    
    
<select id="combo1" onchange="getCombo1(this)">
  <option value="ka">Karnataka</option>
  <option value="tn">Tamilnadu</option>
   <option value="ap">Andrapradesh</option>
  <option value="mh">Maharashtra</option>
</select>

  <pre id="test">



</body>

it will display the output in p tag
but i want it to b displayed in this 
<select id="Select1">
        <option></option>
    </select>

("#test").load("test.aspx?test=" + value); } </script> </head> <body> <select id="combo1" onchange="getCombo1(this)"> <option value="ka">Karnataka</option> <option value="tn">Tamilnadu</option> <option value="ap">Andrapradesh</option> <option value="mh">Maharashtra</option> </select> <pre id="test">



</body>

it will display the output in p tag
but i want it to b displayed in this 
<select id="Select1">
        <option></option>
    </select>


This is not exactly "combo box"; this is HTML select element. By "display", you may mean selecting the item (option element) depending on some value you

Of course, you cannot use jQuery .load here. Please see what it does:
https://api.jquery.com/load[^].

It places some HTML in the element. This is not what you want. You want to remove selected attribute from one option element and either add this attribute to some other (or maybe the same) element, or none of them, in case there is no match.

The implementations of these operations are explained here; please see top answer to the question: http://***.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery[^].

Instead of .load, you need to just extract the value from service. Use general-purpose jQuery Ajax: http://api.jquery.com/jquery.ajax[^].

That's all. As you can see, this is considerably more tricky than .load, but nothing too hard.

—SA