解决了...你可以关闭...
我有一个下拉菜单和一个文本区域,我可以在其中输入不同的文字,具体取决于在下拉菜单中选择的项目(动态)。
我的 html-php 代码是这样的:
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-2.0.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#copyright_titles').change(function () {
var isFirstSelected = $("#copyright_titles option:first-child" ).is(':selected');
var isLastSelected = $("#copyright_titles option:last-child" ).is(':selected');
if (isFirstSelected) {
$('#copyright_text').hide();
return;
}
$('#copyright_text').attr("readonly",isLastSelected?false:true);
$.ajax({ type: "GET", url: "copyrights.xml", dataType: "xml", success: function(xml) {
$(xml).find('copyright').each(function() {
var copyright_title_selected = $("#copyright_titles option:selected").text();
var title = $(this).find('title').text();
var text = $(this).find('text').text();
if (title === copyright_title_selected) {
$('#copyright_text').text(text);
}
});
},
error: function(request, error, tipo_errore) { alert(error+': '+ tipo_errore); }
});
$('#copyright_text').show();
});
});
</script>
</head>
<body>
<form name="test" action="test.php" method="post">
<table>
<tr>
<td>Copyright:</td>
<td>
<select id='copyright_titles'>
<?php
$xml = simplexml_load_file('copyrights.xml');
$i = 0;
foreach($xml->copyright as $copyright)
{
$i++;
echo '<option value="copyright'.$i.'">'.$copyright->title.'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td></td><td>
<textarea id='copyright_text' rows="6" cols="65" style="display:none"></textarea>
</td>
</tr>
</table>
</form>
</body>
文本来自此 xml 文件:
<copyrights>
<copyright>
<title>free</title>
<text></text>
</copyright>
<copyright>
<title>copyright1</title>
<text>text1</text>
</copyright>
<copyright>
<title>copyright2</title>
<text>text2</text>
</copyright>
<copyright>
<title>copyright3</title>
<text>text3</text>
</copyright>
<copyright>
<title>other</title>
<text></text>
</copyright>