[英]JS simple function call is not working
即時消息對codeginiter及其開發而言。 我在這里按下選項時使用了保管箱(html選擇框)。 我需要觸發一個警報box.in oder來做到這一點,我用下面的代碼。 但這對我沒有用。 我可以找到我做的錯誤,請幫助我。
<html lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Ask Questions</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="<?php echo base_url(); ?>css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo base_url(); ?>css/style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.min.js">
// untill select catogory tags are disabled
function activate_match()
{
// var tnmt_id = "hip hure";
alert("tested");
//Get the id of the tournament selected in the list
}
</script>
</head>
<body>
<div class="container">
<p class="help-block">
How to Ask </br>
Is your question about DIY ? </br>
We prefer questions that can be answered, not just discussed.<br>
Provide details. Share your experience. </br>
</p>
<div class="form-group">
<?php
echo form_open('homepage/askquestionview');
echo validation_errors();
?>
</div>
<p> </p>
<div class="form-group">
<select name="cat" id="cat" onchange="activate_match()">
<?php
foreach($catogories as $cat) {
echo'<option value="' . $cat . '">' . $cat . '</option>';
}
?>
</select>
</div>
<div class="form-group">
<p>
Description: <br/>
<textarea name="decription" rows="5" cols="100"> </textarea>
</p>
</div>
<p></p>
<div class="form-group">
Declare new Tags:<br/>
<input type="text" value="" name="tag">
</p>
</div>
</div> <p>
<input type="submit" class="btn btn-success btn-block" value="Post Your Question" id="postQuestion">
</p>
<?php echo form_close(); ?>
</body>
</html>
您需要具有兩個單獨的script
標簽:
<script src="<?php echo base_url(); ?>js/jquery.min.js"></script>
<script>
function activate_match() {
// var tnmt_id = "hip hure";
alert("tested");
//Get the id of the tournament selected in the list
}
</script>
如果script
具有src
屬性,則其內部內容將被忽略。 因此,第一個腳本是加載jQuery,第二個腳本是聲明您的函數。
您不應該使用內聯JavaScript。 由於您有可用的jQuery,因此應該可以解決問題:
$(document).ready(function(){
$('#cat').change(function(){
alert('Tested! Current select value is: ' + $(this).val());
});
});
另外,需要為您的自定義代碼使用單獨的腳本標簽,並為包含文件使用單獨的腳本標簽-您已將函數嵌入jQuerys腳本標簽中,這就是為什么它不起作用的原因。
改變HTML
<select name="cat" id="cat" onchange="activate_match(this.value)">
<?php
foreach($catogories as $cat) {
echo'<option value="' . $cat . '">' . $cat . '</option>';
}
?>
</select>
在您的腳本中
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.min.js"></script>
<script>
// untill select catogory tags are disabled
function activate_match(id)
{
// var tnmt_id = "hip hure";
alert(id);
//Get the id of the tournament selected in the list
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.