我正在尝试从下拉列表中获取所选选项的ID。我试过这样的:
<a id="edit_link" href=""><button>Edit</button> </a>
然后在javascript中我喜欢这样:
<script type="text/javascript">
$(document).ready(function() {
$('#base_ini_id').change(function() {
var id = $("#base_ini_id").val();
$("#edit_link").attr("href","/customer/upload_ini/edit_ini_old/"+id);
});
});
</script>
我的当前网址是:
/customer/user/edit/1
现在在这个页面上我有另一个编辑按钮指向:
/customer/upload_ini/edit_ini_old/1
但是,当我点击该按钮时,它会转到:
/customer/user/edit/1
这是为什么?以下是我的代码:
<tr>
<?php
if (isset($_GET['id']))
{
$id = $_GET['id'];
btn_edit($id);
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<td>
<select required name="base_ini_id" id="base_ini_id" class="form-control">
<option value="">Select</option>
<?php foreach($base as $value) { ?>
<option id="emp" class="specialLink" value="<?php echo $value->id;?>">
<?php echo $value->base_ini_filename;?>
</option>
<?php } ?>
</select>
</td>
<td>
<a id="edit_link" href="/customer/upload_ini/edit_ini_old/">
<button>Edit</button>
</a>
</td>
<script type="text/javascript">
$(document).ready(function() {
$('#base_ini_id').change(function() {
var id = $("#base_ini_id").val();
$("#edit_link").attr("href","/customer/upload_ini/edit_ini_old/" + id);
});
});
</script>
</tr>
答案 0 :(得分:0)
我使用这个脚本得到了答案:
<tr>
<td>Base INI File</td>
<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
btn_edit_file($id);
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<td>
<select required name="base_ini_id" id="base_ini_id" class="form-control">
<option value="">Select</option>
<?php foreach($base as $value)
{
?>
<option id="emp" class="specialLink" value="<?php echo $value->id;?>"
<?php if($value->id == $user->base_ini_id){echo "selected";} ?>>
<?php echo $value->base_ini_filename;?></option>
<?php } ?>
</select>
</td>
<td>
<?php echo btn_edit('customer/upload_ini/edit_ini_custom/'); ?>
</td>
<script type="text/javascript">
$(document).ready(function() {
$('#base_ini_id').change(function() {
var id = $("#base_ini_id").val();
var url = "/bizrtc/customer/upload_ini/edit_ini_custom/";
$("#edit_link").attr("href",url+ id);
$("#edit_link").attr("target","_blank");
});
});
</script>
</tr>