如何通过附加到多个表单操作的jquery发送变量?我需要能够使用表单操作发送#clientId#,但我在jquery中设置表单操作,具体取决于用户选择的下拉选项。例如: if($('#uTransaction')。val()== 1){ $('#toolActions&#39)。ATTR('动作',' networkTools-transfer.cfm otherID =#的clientId#?); < - 这不起作用 }
这是我的代码:
HTML
<form id="toolActions" name="toolActions" method="post" action="">
<div id="action-div">
<table class="action-table">
<tr class="action-row">
<td>Selected Tools Action:
<select name="uTransaction" id="uTransaction" >
<option value="">--Select One--</option>
<cfloop query="networkTool_Actions">
<cfoutput><option value="#networkTool_Actions.Tool_Actions_ID#">#networkTool_Actions.Tool_Actions_DESC#</option></cfoutput>
</cfloop>
</select>
</div>
</form>
jQuery
$('#toolActions').submit(function() {
if($('#uTransaction').val() == 1){
$('#toolActions').attr('action','networkTools-transfer.cfm');
}
if($('#uTransaction').val() == 2){
$('#toolActions').attr('action','networkTools-accept.cfm');
}
if($('#uTransaction').val() == 3){
$('#toolActions').attr('action','networkTools-retire.cfm');
}
if($('#uTransaction').val() == 4){
$('#toolActions').attr('action','networkTools-recover.cfm');
}
if($('#uTransaction').val() == 5){
$('#toolActions').attr('action','networkTools-repair.cfm');
}
});
答案 0 :(得分:0)
你可以试试这个:
$('input').on('some event',function(){
$('form').get(0).setAttribute('action', 'create_new_url');
}
我想这会像&#39; select&#39;在&#39;模糊&#39; /&#39;改变&#39;可能?
这是一个小伙伴 http://jsfiddle.net/95gff/
更改选择输入时,请通过firebug或首选调试器检查表单上的操作 而且你会看到行动确实发生了变化。
答案 1 :(得分:0)
试试这个:
<script>
$('#uTransaction').change(function() { //when you will select any option in dropdown
var val=$('#uTransaction').val();//get value of that option
if(val == 1){
window.location.href='networkTools-transfer.cfm?otherID='+val;
}
if(val == 2){
window.location.href='networkTools-accept.cfm?otherID='+val;
}
if(val == 3){
window.location.href='networkTools-retire.cfm?otherID='+val;
}
if(val == 4){
window.location.href='networkTools-recover.cfm?otherID='+val;
}
if(val == 5){
window.location.href='networkTools-repair.cfm?otherID='+val;
}
});
</script>
if user wants form to submit ,then try this
<script>
$('#uTransaction').change(function() { //when you will select any option in dropdown
var val=$('#uTransaction').val();//get value of that option
if(val == 1){
$('#toolActions').attr('action','networkTools-transfer.cfm?otherID='+val);
}
if(val == 2){
$('#toolActions').attr('action','networkTools-accept.cfm?otherID='+val);
}
});
</script>
and add this in html:
<input type="submit" name="" value="submit"/>