获取文本选择Runat =" Server" [英] Get Text Select That Runat="Server"

查看:59
本文介绍了获取文本选择Runat =" Server"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   <select   id="Select1">
         <option>1</option>
         <option>2</option>
         <option>3</option>
  </select>

alert($("#Select1").val());

此代码是正确的并且返回当前值。

this code Is Correct And Return Current Value.

   <select runat="server"   id="Select1">
         <option></option>
  </select>

function parseXmlQuestion(xml)
{

   $(xml).find("Question").each(function()
  { 
     var value=$(this).find('Text').text()
     $('#<%=Select1.ClientID %>').
      append($("<option></option>").
      attr("value",value).
      text(value)); 
   });

}

alert( $('#<%=Select1.ClientID %>').val());
alert( $('#<%=Select1.ClientID %> option:selected').val());

alert( $('#<%=Select1.ClientID %>').text());
alert( $('#<%=Select1.ClientID %> option:selected').val());

alert( $('#<%=Select1.ClientID %>').html());
alert( $('#<%=Select1.ClientID %> option:selected').val());

返回null或undefined。

return null or undefined .

推荐答案

好的,你有点奇怪,每次回答你都会帮助我们...

Ok you are a bit weird and you are helping us less each time you answer...

这是你应该做的。


  1. 测试这会返回正确的ID。 <%= Select1.ClientID%> 应为 Select1

  2. 检查你的xml,即正确,(使用json,这更容易),包括你的xml标签的大写。所以要么 console.log(value)或者 alert(value)如果你还没有进化过:)

  3. parseXmlQuestion()应该在页面的某个地方调用,否则你只是坐着的鸭子没被射击或没有告诉它在换句话说

  1. test that this returns the correct id. <%=Select1.ClientID %> which should be Select1
  2. check your xml, that is, correct, (use json preferably it's far easier) including the caps of your xml tags. so do either console.log(value) or alert(value) if you haven't evolved yet :)
  3. parseXmlQuestion() should be called somewhere on the page otherwise you just having a sitting duck not being shot or not telling it to run in other words

这篇关于获取文本选择Runat =&quot; Server&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆