English 中文(简体)
选择所有选择
原标题:Select all options in select

我有多个选择。 怎样才能选择所有备选办法? 或者,如何选择所有备选办法。 我只有几类(非国际发展法)。

最佳回答

我认为,你甚至可以写上你这样的替换线:

$(".someClass option").attr("selected", "selected");

避免<代码>。

问题回答

这里略微改动了基套式编码,以确保你能够选择子/电文控制,如果你只拥有阶级,而不是id。

<html id="html">
<body id="body">
<script src="file:\D:Sidharthjavascriptjquery-1.4.2.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

        function SelectAll() {
            $(".someClass").children().each(function () { $(this).attr("selected", "selected"); });
        }

        $(".clickme").bind("click", SelectAll);


    });
</script>
<input type="submit" class="clickme" />
<select multiple="yes" class="someClass">
<OPTION VALUE="1" id="one">Option 1</OPTION> 
<OPTION VALUE="2" id="two">Option 2</OPTION> 
<OPTION VALUE="3" id="three">Option 3</OPTION> 
<OPTION VALUE="4" id="four">Option 4</OPTION> 
</select>

</div>
</body>
</html>

如果你为纽顿或选择发身份证,就用字母编号取代。 例如,如果 but子的id点被点击,而不是仅仅使用板块,而不是像。

希望是你们重新寻找的。

我确信这不是100%,这是你要求的东西,但这里是:

<SELECT MULTIPLE="yes" ID="multipleSelect">
<OPTION VALUE="1" SELECTED="selected">Option 1</OPTION>
<OPTION VALUE="2" SELECTED="selected">Option 2</OPTION>
<OPTION VALUE="3" SELECTED="selected">Option 3</OPTION>
<OPTION VALUE="4" SELECTED="selected">Option 4</OPTION>
<OPTION VALUE="5" SELECTED="selected">Option 5</OPTION>
<OPTION VALUE="6" SELECTED="selected">Option 6</OPTION>
</SELECT>

<INPUT TYPE="submit" ID="submit" value="Go!"/>

动态选择(与 j合):

$("#submit").click(function() {  
  $("#multipleSelect option").each(function() {
    $(this).attr("selected", "selected");
  });
});

未经测试。

Good luck.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签