我需要幫助,找出方法來提供一個按鈕來重置這些複選框。添加重置按鈕重置複選框使用PHP或JavaScript
UPDATEL:我有更多的信息分享到:
提供的答案將只能與與被啓用的onLoad該實例,而不是複選框選中複選框工作。這是一個推理頁面,人們可以選擇他們喜歡的流派並保存它們。
<div class="grid_13">
<form method="post" id="updatePreferedGenres" action="/account/update/preferences/genres">
<h2 class="alt blue no-margin-top margin-bottom">Check off genres you like:</h2>
<?php
$this->load->library('GenreLib');
$genreArray = $this->genrelib->getGenreList();
foreach ($genreArray as $parentID => $genreSegment){
$isChecked = "";
if (isset($customerPrefs['genres']) && is_array($customerPrefs['genres']) && sizeof($customerPrefs['genres']) > 0 && in_array($parentID, array_keys($customerPrefs['genres']))) {
$isChecked = "CHECKED";
}
echo '<p class="grid_3 no-margins-left no-margins-right"><input type="checkbox" class="margin-right" name="' . $genreSegment['parentGenreName'] . '" value="' . $parentID . '"' . $isChecked . '/>' . $genreSegment['parentGenreName'] . '</p>';
}
?>
<div class="clear"></div>
<input type="button" class="button right" value="Save" />
<div class="clear"></div>
</form>
// Rig the preferences form
$("#updateDHOverride").submit(function(event) {
event.preventDefault();
if ($(this).find("#downloadHubOverride").is(':checked')){
document.cookie = 'downloadHubOverride=TRUE; expires=Thursday, 25-Jul-2030 23:59:59 GMT; path=/';
}
else {
document.cookie = 'downloadHubOverride=FALSE; expires=Thursday, 25-Jul-2030 23:59:59 GMT; path=/';
}
});
// Rig the submit for genre preferences form
$("#updatePreferedGenres").each(function() {
var linkedForm = $(this);
$(this).find("#prefSave").click(function(event) {
event.preventDefault();
var getGenreIds = "";
linkedForm.find("input[type=checkbox]").each(function() {
if ($(this).is(":checked")) {
if (getGenreIds.length > 0) {
getGenreIds += ',' + $(this).attr('value');
}
else {
getGenreIds += $(this).attr('value');
}
}
});
$.post(
linkedForm.attr('action'),
{ genreIds : getGenreIds },
function (status) {
status = $.parseJSON(status);
if (status.status == "success") {
$.prompt('<h4>Preferences updated successfully!</h4>', {
top: '34%',
zIndex: '10000'
});
if (linkedForm.hasClass('goHome')) window.location = "/";
}
else {
$.prompt('<h4>' + status.message + '</h4>', {
top: '34%',
zIndex: '10000'
});
}
}
);
});
});
// REMOVE checkboxes Script - need to place into onClick Function
// $('input:checkbox').removeAttr('checked');
$('#activateAccount').submit(function(event) {
event.preventDefault();
// update form update action
$.post(
$(this).attr('action'),
$(this).serialize(),
function (status) {
//console.log(status);
status = $.parseJSON(status);
if (status.status == "success") {
$.prompt('<h4>Account updated successfully!</h4>', {
top: '34%',
zIndex: '10000',
buttons: { OK:true },
submit: function(v,m,f){
location.reload(true);
}
});
}
else {
if (status.data != "") {
//if there are form validation errors
displayValidation(status.data);
}
else {
//generic error message
$.prompt('<h4>' + status.message + '</h4>', {
top: '34%',
zIndex: '10000'
});
}
}
}
);
});
我有什麼需要做一個基本的想法,我只是不知道在語法。
'<輸入名稱= 「復位」 TYPE = 「復位」 值=「復位「/>' – j08691 2012-02-27 21:01:01
是否要取消選中所有複選框或將它們重置爲原始值? – 2012-02-27 21:03:12
添加具有重置類型的另一個輸入按鈕似乎不起作用 - 將其視爲提交按鈕。 – TrevorD 2012-02-27 23:34:31