HTML 操作 ID 获取方法
HTML Action ID get method
这可能已经是另一个问题的副本,但我找不到它。
我的表单中有一个动作:
<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post">
现在我的系统的工作方式是每个 "bugs" 需要更新的都有自己的错误 ID,通常这会转到错误 ID 的末尾,以允许用户更新所述错误。
我在 Yii 中创建了一些 json 代码来显示错误 ID 和编辑。
问题是当我单击编辑时。它转到表单上没有 ID 的页面。我需要一些方法让该 ID 移动到表单中。
这是我为表单准备的所有代码。
<!--PAGE -->
<div data-role="page" id="Reg">
<header role="banner" data-role="header" id="header" style="height:45px; z- index:1"> <a data-icon="back" data-role="button" data-rel="back" class="ui-btn- left backToAdmin">Back</a> </header>
<!--Initial Home Screen Logo-->
<section data-role="content" class="constrain headerLogo" > </section>
<!--Main Content in Center of Screen-->
<section data-role="content" class="sectionContent constrain">
<!--960 Grid Root [responsive web design plugin]-->
<div class="container_16" data-theme="a">
<div class="grid_16">
<div class="gridMarginsLeft">
<ul id="viewProps" data-role="listview" data-inset="true" data-theme="a" data-icon="false" class="">
<li data-role="list-divider" data-theme="a"><span class="icon-data fontIcons"></span><span class="coloumnHeaders">Update</span></li>
<li data-role="list-divider" data-theme="a">
<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post">
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<label for="Bug_bugname">Bugname</label> <textarea rows="6" cols="50" name="Bug[bugname]" id="Bug_bugname">1</textarea> </div>
<div class="row">
<label for="Bug_BugType">Bug Type</label> <input name="Bug[BugType]" id="Bug_BugType" type="text" value="1"> </div>
<div class="row">
<label for="Bug_Bugaddress">Bugaddress</label> <input size="60" maxlength="255" name="Bug[Bugaddress]" id="Bug_Bugaddress" type="text" value="1"> </div>
<div class="row">
<label for="Bug_description">Description</label> <textarea rows="6" cols="50" name="Bug[description]" id="Bug_description">1</textarea> </div>
<div class="row">
<label for="Bug_admin_id">Admin</label> <input name="Bug[admin_id]" id="Bug_admin_id" type="text" value="1"> </div>
<div class="row">
<label for="Bug_status">Status</label> <input size="3" maxlength="3" name="Bug[status]" id="Bug_status" type="text" value="1"> </div>
<div class="row">
<label for="Bug_type">Type</label> <input size="20" maxlength="20" name="Bug[type]" id="Bug_type" type="text" value="1"> </div>
<div class="row">
<label for="Bug_vendors_id">Vendors</label> <input name="Bug[vendors_id]" id="Bug_vendors_id" type="text" value="1"> </div>
<div class="row buttons">
<input type="submit" name="yt0" value="Save"> </div>
</form>
</li>
</ul>
</div>
</div>
</div>
向表单添加隐藏输入。我 fthe id 在变量名 $id:
form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post">
<input type="hidden" name="id" value="$id" />
</form>
要将 id 放入 URL 路径,请将 $id 附加到操作路径。
form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/$id" method="post">
在您的表单中添加一个隐藏的输入字段标签,并将 id 作为其值。
<input type="hidden" id="bug_id" name="bug_id" value="$id" />
并使用javascript/jquery代码来改变你的动作url(这里我使用了jquery):
$(文档).ready(函数(){
$('#bug-form').submit(function(){
//append your bug id to the action url
var updateUrl = $(this).attr('action') +$('#bug_id').val();
//update your action url of the form
$(this).attr('action',updateUrl);
});
});
这可能已经是另一个问题的副本,但我找不到它。
我的表单中有一个动作:
<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post">
现在我的系统的工作方式是每个 "bugs" 需要更新的都有自己的错误 ID,通常这会转到错误 ID 的末尾,以允许用户更新所述错误。
我在 Yii 中创建了一些 json 代码来显示错误 ID 和编辑。 问题是当我单击编辑时。它转到表单上没有 ID 的页面。我需要一些方法让该 ID 移动到表单中。
这是我为表单准备的所有代码。
<!--PAGE -->
<div data-role="page" id="Reg">
<header role="banner" data-role="header" id="header" style="height:45px; z- index:1"> <a data-icon="back" data-role="button" data-rel="back" class="ui-btn- left backToAdmin">Back</a> </header>
<!--Initial Home Screen Logo-->
<section data-role="content" class="constrain headerLogo" > </section>
<!--Main Content in Center of Screen-->
<section data-role="content" class="sectionContent constrain">
<!--960 Grid Root [responsive web design plugin]-->
<div class="container_16" data-theme="a">
<div class="grid_16">
<div class="gridMarginsLeft">
<ul id="viewProps" data-role="listview" data-inset="true" data-theme="a" data-icon="false" class="">
<li data-role="list-divider" data-theme="a"><span class="icon-data fontIcons"></span><span class="coloumnHeaders">Update</span></li>
<li data-role="list-divider" data-theme="a">
<form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post">
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<label for="Bug_bugname">Bugname</label> <textarea rows="6" cols="50" name="Bug[bugname]" id="Bug_bugname">1</textarea> </div>
<div class="row">
<label for="Bug_BugType">Bug Type</label> <input name="Bug[BugType]" id="Bug_BugType" type="text" value="1"> </div>
<div class="row">
<label for="Bug_Bugaddress">Bugaddress</label> <input size="60" maxlength="255" name="Bug[Bugaddress]" id="Bug_Bugaddress" type="text" value="1"> </div>
<div class="row">
<label for="Bug_description">Description</label> <textarea rows="6" cols="50" name="Bug[description]" id="Bug_description">1</textarea> </div>
<div class="row">
<label for="Bug_admin_id">Admin</label> <input name="Bug[admin_id]" id="Bug_admin_id" type="text" value="1"> </div>
<div class="row">
<label for="Bug_status">Status</label> <input size="3" maxlength="3" name="Bug[status]" id="Bug_status" type="text" value="1"> </div>
<div class="row">
<label for="Bug_type">Type</label> <input size="20" maxlength="20" name="Bug[type]" id="Bug_type" type="text" value="1"> </div>
<div class="row">
<label for="Bug_vendors_id">Vendors</label> <input name="Bug[vendors_id]" id="Bug_vendors_id" type="text" value="1"> </div>
<div class="row buttons">
<input type="submit" name="yt0" value="Save"> </div>
</form>
</li>
</ul>
</div>
</div>
</div>
向表单添加隐藏输入。我 fthe id 在变量名 $id:
form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post">
<input type="hidden" name="id" value="$id" />
</form>
要将 id 放入 URL 路径,请将 $id 附加到操作路径。
form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/$id" method="post">
在您的表单中添加一个隐藏的输入字段标签,并将 id 作为其值。
<input type="hidden" id="bug_id" name="bug_id" value="$id" />
并使用javascript/jquery代码来改变你的动作url(这里我使用了jquery):
$(文档).ready(函数(){
$('#bug-form').submit(function(){
//append your bug id to the action url
var updateUrl = $(this).attr('action') +$('#bug_id').val();
//update your action url of the form
$(this).attr('action',updateUrl);
});
});