gpt4 book ai didi

javascript - .click() 函数不起作用 javascript/jquery

转载 作者:行者123 更新时间:2023-11-28 04:44:43 29 4
gpt4 key购买 nike

更新:

不知何故,我尝试后效果很好..

更新

我正在使用.click()在我的 javascript 上运行,但它不起作用。

这是我的 JS 代码:

src="jquery.js";
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
var institutionID, acadCareerID;
$(document).ready(function(){


getInstitution();

institutionID = $( "select#institution option:checked" ).val();
if(institutionID == null){
institutionID = 1;
}

getAcadCareerByInstitution(institutionID);

acadCareerID = $( "select#acadCareer option:checked" ).val();
if(acadCareerID == null){
acadCareerID = 1;
}

getPeriodByAcadCareerAndInstitution(acadCareerID);
getDepartmentByAcadCareer(acadCareerID);



$("select#institution").change(function(){
institutionID = $( "select#institution option:checked" ).val();
getAcadCareerByInstitution(institutionID);
})
$("select#acadCareer").change(function(){
acadCareerID = $( "select#acadCareer option:checked" ).val();
getPeriodByAcadCareerAndInstitution(acadCareerID);
getDepartmentByAcadCareer(acadCareerID);
})


$("div#search").click(function(){
alert("The paragraph was clicked.");
console.log("abc");
});

});

所有功能如 getInstituion() , getAcadCareerByInstitution(institutionID)等等都是ajax调用。

这是我的 HTML 代码:

<form action="doInsertSchedule" method="POST" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label for="institution">Institution</label>
<select name="institution" class="form-control" id="institution">
</select>
</div>
<div class="form-group">
<label for="acadCareer">Academic Career</label>
<select name="acadCareer" class="form-control" id="acadCareer">
</select>
</div>
<div class="form-group">
<label for="period">Period</label>
<select name="period" class="form-control" id="period">
</select>
</div>
<div class="form-group">
<label for="department">Department</label>
<select name="department" class="form-control" id="department">
</select>
</div>
<div class="form-group">
<label for="date">Deadline Date</label>
<input type="date" class="form-control" id="deadline" placeholder="Deadline Date" name="deadline">
</div>

<button type="submit" class="btn btn-default">Submit</button>
<div id="search" class="btn btn-default">Search</div>
</form>

我已经为我的主布局(Laravel 5)添加了 jquery

<head>
<link rel="stylesheet" type="text/css" href="{{url()}}/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="{{url()}}/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="{{url()}}/js/tools.js"></script>
<script src="{{url()}}/js/bootstrap.min.js"></script>
<title>BINUS - @yield('title')</title>
<meta name="csrf-token" content="{{ csrf_token() }}" />
</head>

我希望搜索按钮/Div 在单击时执行某些操作。我看不出这里出了什么问题。

我已经尝试过<div><button>但它就像提交一样工作。我也已经尝试输入 event.preventDefault()在我的 JS 代码中,但它也不起作用。

最佳答案

也许您可以尝试使用事件委托(delegate)...

$(document).ready(function(){

$("body").on("click", "#search", function(){
alert("The paragraph was clicked.");
console.log("abc");
});

});

关于javascript - .click() 函数不起作用 javascript/jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43484926/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com