将代码作为外部文件放置后,Javascript代码不起作用 [英] Javascript code doesn't work after putting the code as external file
问题描述
我正在为页面中的引导程序模式(弹出窗口)应用Javascript(JS)代码.我打算让它动态运行,因为我在弹出窗口中显示的文本框中输入了输入.以前,当我将JS代码放在布局页面中时,它可以工作.但是,当我尝试将代码放在文件夹中的单独JS文件中时,它不再起作用.为什么是这样?当我单击按钮时,将出现弹出窗口,但是当我输入输入或单击弹出窗口中的按钮时,它不起作用.我确保文件目录不是问题.
I'm applying a Javascript (JS) code for bootstrap modal(popup window) in my page. I'm planning to let it run dynamically as i enter an input into the textbox that appears from the popup window. Previously when i put the JS code in the layout page, it works. But when i tried to put the code in a separate JS file in a folder, it doesn't work anymore. Why is this? When i click the button, the popup window appears but when i entered input or clicked a button in the popup window, it didn't work. I've ensured that the file directory is not the problem.
我也放了
<script type="text/javascript" src="~/Script/Modal.js"></script>
位于布局的开头部分,以确保将其动态加载.
at the head section of the layout to ensure that it will be loaded dynamically.
这是我放入Modal.js文件中的内容.是正确的还是我错过了什么?我在代码之间确实有一个if子句.
This is what i put in my Modal.js file. Is it correct or am i missing something? I do have an if clause in between the codes.
$(function() {
// New Modal ================================================
$('#inputNew').on('hidden.bs.modal', function (e) {
document.getElementById("inputNewCheckbox").checked = true;
document.getElementById("inputMother").style.display = 'block';
document.getElementById("inputMotherlabel").style.display = 'block';
var value = $('#myPopupInput1').val();
$('#inputMother').val(value);
$('#inputNew').modal('hide');
});
$('#inputNew').on('click', '#SearchMother', function () {
var value = $('#myPopupInput1').val();
$('#inputMother').val(value);
$('#inputNew').modal('hide');
});
if ($checkbox.data('waschecked') == true && $('#inputMother') != '') {
if ($('#inputNewCheckbox').on("click", function () {
$('#inputNewCheckbox').prop('checked', false);
}));
}
})
这是在查看"页面中输入的复选框
This is the checkbox input in the View page
<input type="checkbox" name="inputNew" value="inputNew" id="inputNewCheckbox" data-toggle="modal" data-target="#inputNew" data-waschecked="false"> New
推荐答案
尝试将您的代码放入document.ready
try putting your code in document.ready
$(document).ready(function () {
// New Modal ================================================
$('#inputNew').on('hidden.bs.modal', function (e) {
document.getElementById("input").checked = true;
});
})
这篇关于将代码作为外部文件放置后,Javascript代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!