对变化中选择加载使用jQuery负荷另一个选择选项 [英] on change select load another select options using jquery load

查看:128
本文介绍了对变化中选择加载使用jQuery负荷另一个选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的Javascript,低于与course_name的ID和日期

的ID一个div一个选择框

 <脚本>
$('#course_name')。改变(函数(){
    URL =date_range.php courseID =$('#course_name)VAL()。
  $(#日期)。载荷(URL)
});

< / SCRIPT>
 

当我打电话date_range.php?courseID = 1,通过我的浏览器,它显示的日期,但code以上没有加载。

解决方案

  URL =date_range.php courseID =?+ $('#course_name)VAL()。
 

或者更好的是,

  URL =date_range.php courseID =?+ parseInt函数($('#course_name)VAL());
 

第二个将始终返回一个号码,这样它的0(零)或以上,如果#course_name值是一个非数字编号,将返回零,否则返回数...当你想这是非常有用的验证服务器上的值。

Here is my Javascript which is below a select box with the id of "course_name" and a div with an id of "dates"

<script>
$('#course_name').change(function() {
    url = "date_range.php?courseID=".$('#course_name').val();
  $("#dates").load(url)
});

</script>

when i call date_range.php?courseID=1 through my browser it displays the dates but the code above is not loading.

解决方案

url = "date_range.php?courseID="+$('#course_name').val();

or better still,

url = "date_range.php?courseID="+parseInt($('#course_name').val());

the second one will always return a number so it's either 0 (zero) or above, if the #course_name value is a non numeric number it would return zero, otherwise returns the number... this is especially useful when you want to validate the value on the server.

这篇关于对变化中选择加载使用jQuery负荷另一个选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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