向页面添加第二个脚本时出现Javascript问题
两个JS脚本都可以工作。我的问题是,在添加第二个JS脚本时,第一个JS不起作用。我怎样才能解决这个问题 第一个JS脚本向页面添加第二个脚本时出现Javascript问题,javascript,php,css,Javascript,Php,Css,两个JS脚本都可以工作。我的问题是,在添加第二个JS脚本时,第一个JS不起作用。我怎样才能解决这个问题 第一个JS脚本 <script> $(document).ready(function(){ $("button1").click(function(){ $("div1").toggleClass("grid"); }); }); </script> <script> var $j = jQuery.noConflict
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("#trigger").change(function () {
if ($j(this).data('options') == undefined) {
$j(this).data('options', $j('select.switchable option').clone());
}
var id = $j(this).val();
var that = this;
$j("select.switchable").each(function () {
var thisname = $j(this).attr('name');
var theseoptions = $j(that).data('options').filter('.' + thisname + '_' + id);
$j(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$j('#trigger').trigger('change');
});
</script>
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
$(document).ready(function () {
$("#trigger").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('select.switchable option').clone());
}
var id = $(this).val();
var that = this;
$("select.switchable").each(function () {
var thisname = $(this).attr('name');
var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
$(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$('#trigger').trigger('change');
});
</script>
$(文档).ready(函数(){
$(“按钮1”)。单击(函数(){
$(“div1”).toggleClass(“网格”);
});
});
第二个JS脚本
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("#trigger").change(function () {
if ($j(this).data('options') == undefined) {
$j(this).data('options', $j('select.switchable option').clone());
}
var id = $j(this).val();
var that = this;
$j("select.switchable").each(function () {
var thisname = $j(this).attr('name');
var theseoptions = $j(that).data('options').filter('.' + thisname + '_' + id);
$j(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$j('#trigger').trigger('change');
});
</script>
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
$(document).ready(function () {
$("#trigger").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('select.switchable option').clone());
}
var id = $(this).val();
var that = this;
$("select.switchable").each(function () {
var thisname = $(this).attr('name');
var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
$(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$('#trigger').trigger('change');
});
</script>
var$j=jQuery.noConflict();
$j(文档).ready(函数(){
$j(“#触发器”).change(函数(){
if($j(this).data('options')==未定义){
$j(this).data('options',$j('select.switchable option').clone());
}
var id=$j(this.val();
var=这个;
$j(“选择.可切换”)。每个(功能(){
var thisname=$j(this.attr('name');
var theseoptions=$j(that).data('options').filter('.'.+thisname+'.'+id);
$j(this.html)(选项);
});
});
//然后将其关闭一次以显示正确的元素
$j(“#trigger”).trigger('change');
});
您应该以同样的方式尊重所有准备好文档的功能:
通过删除j并仅使用$
第一个JS脚本
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("#trigger").change(function () {
if ($j(this).data('options') == undefined) {
$j(this).data('options', $j('select.switchable option').clone());
}
var id = $j(this).val();
var that = this;
$j("select.switchable").each(function () {
var thisname = $j(this).attr('name');
var theseoptions = $j(that).data('options').filter('.' + thisname + '_' + id);
$j(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$j('#trigger').trigger('change');
});
</script>
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
$(document).ready(function () {
$("#trigger").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('select.switchable option').clone());
}
var id = $(this).val();
var that = this;
$("select.switchable").each(function () {
var thisname = $(this).attr('name');
var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
$(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$('#trigger').trigger('change');
});
</script>
$(文档).ready(函数(){
$(“按钮1”)。单击(函数(){
$(“div1”).toggleClass(“网格”);
});
});
第二个JS脚本
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("#trigger").change(function () {
if ($j(this).data('options') == undefined) {
$j(this).data('options', $j('select.switchable option').clone());
}
var id = $j(this).val();
var that = this;
$j("select.switchable").each(function () {
var thisname = $j(this).attr('name');
var theseoptions = $j(that).data('options').filter('.' + thisname + '_' + id);
$j(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$j('#trigger').trigger('change');
});
</script>
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
$(document).ready(function () {
$("#trigger").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('select.switchable option').clone());
}
var id = $(this).val();
var that = this;
$("select.switchable").each(function () {
var thisname = $(this).attr('name');
var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
$(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$('#trigger').trigger('change');
});
</script>
$(文档).ready(函数(){
$(“#触发器”).change(函数(){
if($(this).data('options')==未定义){
$(this.data('options',$('select.switchable option')).clone();
}
var id=$(this.val();
var=这个;
$(“select.switchable”)。每个(函数(){
var thisname=$(this.attr('name');
var theseoptions=$(that).data('options').filter('.'+thisname+'.'+id);
$(this.html)(选项);
});
});
//然后将其关闭一次以显示正确的元素
$('#trigger')。trigger('change');
});
您应该以同样的方式尊重所有准备好文档的功能:
通过删除j并仅使用$
第一个JS脚本
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("#trigger").change(function () {
if ($j(this).data('options') == undefined) {
$j(this).data('options', $j('select.switchable option').clone());
}
var id = $j(this).val();
var that = this;
$j("select.switchable").each(function () {
var thisname = $j(this).attr('name');
var theseoptions = $j(that).data('options').filter('.' + thisname + '_' + id);
$j(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$j('#trigger').trigger('change');
});
</script>
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
$(document).ready(function () {
$("#trigger").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('select.switchable option').clone());
}
var id = $(this).val();
var that = this;
$("select.switchable").each(function () {
var thisname = $(this).attr('name');
var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
$(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$('#trigger').trigger('change');
});
</script>
$(文档).ready(函数(){
$(“按钮1”)。单击(函数(){
$(“div1”).toggleClass(“网格”);
});
});
第二个JS脚本
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("#trigger").change(function () {
if ($j(this).data('options') == undefined) {
$j(this).data('options', $j('select.switchable option').clone());
}
var id = $j(this).val();
var that = this;
$j("select.switchable").each(function () {
var thisname = $j(this).attr('name');
var theseoptions = $j(that).data('options').filter('.' + thisname + '_' + id);
$j(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$j('#trigger').trigger('change');
});
</script>
<script>
$(document).ready(function(){
$("button1").click(function(){
$("div1").toggleClass("grid");
});
});
</script>
<script>
$(document).ready(function () {
$("#trigger").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('select.switchable option').clone());
}
var id = $(this).val();
var that = this;
$("select.switchable").each(function () {
var thisname = $(this).attr('name');
var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
$(this).html(theseoptions);
});
});
//then fire it off once to display the correct elements
$('#trigger').trigger('change');
});
</script>
$(文档).ready(函数(){
$(“#触发器”).change(函数(){
if($(this).data('options')==未定义){
$(this.data('options',$('select.switchable option')).clone();
}
var id=$(this.val();
var=这个;
$(“select.switchable”)。每个(函数(){
var thisname=$(this.attr('name');
var theseoptions=$(that).data('options').filter('.'+thisname+'.'+id);
$(this.html)(选项);
});
});
//然后将其关闭一次以显示正确的元素
$('#trigger')。trigger('change');
});
接受这个var$j=jQuery.noConflict()代码>从第二个脚本中删除,并将所有$j
引用更改为仅$
。这两个脚本都使用jquery吗?如果是,请删除noConflict并将$j变量更改为$为什么不在一个脚本中同时执行这两个操作?我尝试在一个脚本中同时添加这两个操作并得到相同的结果。因此,您有一个
和
元素?使用这个var$j=jQuery.noConflict()代码>从第二个脚本中删除,并将所有$j
引用更改为仅$
。这两个脚本都使用jquery吗?如果是,请删除noConflict并将$j变量更改为$Why不在一个脚本中同时执行这两个操作?我尝试在一个脚本中同时添加这两个操作并得到相同的结果。因此您有一个
和
元素?