好,可以有兩種情況,即
方案1,你有你的彈出窗口的file.php值數組,
PHP:
/* If you have json in your popup's file.php
You needs to convert the json into php array.
*/
$values_array = json_decode($json_string, true);
/* Initializing default values to the variables that will be used to make selections*/
$check_radio = $check_select = "";
if(is_array($values_array)){
// supposing, the category is for radio buttons
$check_radio = $values_array['category'];
// supposing, the icdcode is for select box
$check_select = $values_array['icdcode'];
}
HTML:
<input type="radio" name="category" value="ICD-10" <?php echo ($check_radio=='ICD-10') ? " checked='checked'":'';?>> ICD-10<br>
<input type="radio" name="category" value="ICD-9" <?php echo ($check_radio=='ICD-9') ? " checked='checked'":'';?>> ICD-9<br>
<select id="icd-code" name="icd-code" multiple>
<option value="1001" <?php echo ($check_select=='1001') ? " selected='selected'":'';?>>1001</option>
<option value="1002" <?php echo ($check_select=='1002') ? " selected='selected'":'';?>>1002</option>
</select>
方案2,您不必在彈出的file.php值或JSON數組的PHP數組,但使用Javascript JSON對象:
// Assuming that you have JSON data like this
// var data = {"cdid":2,"cid":6,"icdcode":"6","category":2};
// So, you will need to Parse Json like this:
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
var parsedData = JSON.parse(data);
// Making Checked the Radio buttons by name `category` and value
$("input[name=category][value='"+parsedData.category+"']").prop("checked",true);
//Making select options selected by option value
$('#icd-code option[value=' + parsedData.icdcode + ']').attr('selected', true);
希望,它會幫助你理清這種情況:)
來源
2016-05-02 09:28:34
hmd
操縱'form'根據返回的值... – Rayon
你能舉幾個例子... –
你能分享一個撥弄着玩? – Rayon