未捕获的TypeError:“#text1”.val不是函数

时间:2017-09-04 16:30:42

标签: javascript php jquery html codeigniter

我有三个html页面

home_frame.html

<html>
<head>
  <script src="<?php echo base_url(); ?>js/jquery.js"></script>
  <script src="<?php echo base_url(); ?>js/myscript.js"></script> 
</head>
<body>
<div class="tab">
    <button  id="button1"          >Button 1</button>
    <button id="button2"   >Button 2</button>
</div>
<div id="bt_one_content" >
</div>
<div id="bt_two_content" >
</div>
</body>
<html>

first.html

<html>
<head></head>
<body>
  <input type="text" id="text1" >
 <input type="button" id="bt_One" value="Say hello Button One">
</body>
</html>

second.html

 <html>
    <head></head>
    <body>
     <input type="text" id="text2" >
     <input type="button" id="bt_two" value="Say hello Button Two">
    </body>
    </html>

当使用jquery和codeigniter点击相应的按钮时,我将first.htmlsecond.html放在home_frame.html

myscript.js

$(document).ready(function(event){

 $("#button1").click(function(event){
    loadFirstView();
 });
 $("#button2").click(function(event){
   loadSecondView();
 });
 $(document).on('click', '#bt_One', function(){
   var val = $("#text1").val();
 });
   $(document).on('click', '#bt_two', function(){
   var val = $("#text2").val();
 });

});
当尝试从动态加载的文本字段中获取文本时,我收到错误

Uncaught TypeError: "#text1".val is not a function

0 个答案:

没有答案