开发者

Selecting a null option

I have a strange problem with this piece of code:

<select name="nazioni" id="nazioni">
  <option selected="selected" value="val">Seleziona</option>
  <option value="0">text 1</option>
  <option value="1">test 2</option>
</select>

The correct behavior with this HTML should be that the selected option is "Seleziona". On some browsers, when I render this HTML, the first option is blank and if I select the value jQuery("#nazioni").val(), I get a null value.

Where is the problem? With the select option in this state, I cannot set any values via jQuery or via any other plugin.

jQuery("#nazioni option:first").attr("selected", "selected"); does not work. I tried using the textotela plugin (http://www.texotela.co.uk/code/jquery/select/), but if I remove the first option using jQuery("#nazio开发者_JS百科ni).removeOption(0), it removes the "Seleziona" value.

Any idea?

Kind regards,

Massimo


Just posting Massimo's comment as an answer to this question:

The problem was that the clearForm() function set the select value to -1.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜