我有一個窗體,其中onsubmit
調用Controller函數,這導致將數據保存在數據庫中。在同一個按鈕上,我需要調用一個Javascript函數。該功能單獨工作,但與控制器,它不owrk。控制器和javascript函數不能一起工作
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Content</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="<?php echo base_url(); ?>stylesheets/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>stylesheets/bootstrap.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>stylesheets/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>stylesheets/bootstrap-theme.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function addinfo()
{
//Create an input type dynamically.
element = document.createElement("button");
element.className='btn btn-default';
var t=document.createTextNode("Edit");
element.appendChild(t);
element.id=t;
//var account=document.getElementById('newaccname').value;
var foo = document.getElementById("acc");
// //Append the element in page (in span).
foo.appendChild(element);
// var d = document.getElementById('acc');
// d.appendChild(i);
}
</script>
</head>
<body>
<?php
echo form_open(base_url() . 'index.php/accounts_controller/addAccount ', array('name' => 'myform'));
?>
<div id='boxed'>
<button type="button" name="addaccount" id="addaccount" class="btn btn-default" data-toggle="modal" data-target="#myModalacc">Add Account</button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModalacc" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add Account</h4>
</div>
<div class="modal-body">
<h5>New Account:</h5>
<input type="text" name="newacc" id="group" placeholder="Account">
<h5>Account Name:</h5>
<input type="text" name="newaccname" id="group" placeholder="Account Name">
<h5>Account Type:</h5>
<select id='acc' name='acc'>
<option value='Facebook'>Facebook</option>
<option value='Twitter'>Twitter</option>
<option value='Google+'>Google+</option>
<option value='LinkedIn'>LinkedIn</option>
<option value='Instagram'>Instagram</option>
<option value='Pinterest'>Pinterest</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<!-- <button type="submit" name="addgroup" class="btn btn-primary" id="add" data-dismiss="modal">Add</button>-->
<button type="submit" name="addaccount" class="btn btn-default" onclick="addinfo()"/>Add
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div id="acc" style="width:500px;height:100px;border:1px solid #000;"></div>
<?php
echo form_close();
?>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<?php echo base_url(); ?>javascripts/bootstrap.min.js"></script>
<script src="<?php echo base_url(); ?>javascripts/bootstrap.js"></script>
</body>
</html>
提供您的代碼示例。 – ripa
當你點擊按鈕 –
什麼是你的控制器文件夾結構?你的控制器的名稱是什麼? – ripa