如何使用jquery和toolpister验证选择选项

时间:2016-03-22 14:12:04

标签: javascript jquery symfony

我想验证我的下拉菜单列表,并检查用户是否选择了not null选项。 这是我的代码:

$('#rappelform input[type="text"]').tooltipster({
  trigger: 'custom', // default is 'hover' which is no good here
  onlyOne: false, // allow multiple tips to be open at a time
  position: 'right' // display the tips to the right of the element
});
$('#rappelform input[type="select"]').tooltipster({
  trigger: 'custom', // default is 'hover' which is no good here
  onlyOne: false, // allow multiple tips to be open at a time
  position: 'right' // display the tips to the right of the element
});

我的HTML标记:

<select id="message" name="message[centre]" class="textbox">
  <option value="">choose value </option>      
  <option value="abc">select 1 </option>  
  <option value="abc">select 2 </option>   
</select>

对于输入文字,我没有任何问题,但使用select选项,如果用户没有选择任何选项,我想显示一条消息。

1 个答案:

答案 0 :(得分:0)

为什么你不使用required属性?

<form>
<select id="message" name="message[centre]" class="textbox" required>
  <option value="">choose value </option>      
  <option value="abc">select 1 </option>  
  <option value="abc">select 2 </option>   
</select>
 <input type="submit"  value="Submit"/>
</form>