Php 使用可编辑下拉列表发布内容
我制作了一个可编辑的下拉菜单:Php 使用可编辑下拉列表发布内容,php,html,Php,Html,我制作了一个可编辑的下拉菜单: <html> <body> <div style="position:relative;width:200px;height:25px;border:0;padding:0;margin:0;"> <select style="position:absolute;top:0px;left:0px;width:200px; height:25px;line-height:20px;margin:0;padding:0
<html>
<body>
<div style="position:relative;width:200px;height:25px;border:0;padding:0;margin:0;">
<select style="position:absolute;top:0px;left:0px;width:200px; height:25px;line-height:20px;margin:0;padding:0;" onchange="document.getElementById('displayValue').value=this.options[this.selectedIndex].text; document.getElementById('idValue').value=this.options[this.selectedIndex].value;">
<option></option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<input type="text" name="displayValue" placeholder="add/select a value" id="displayValue" style="position:absolute;top:0px;left:0px;width:183px;width:180px\9;#width:180px;height:23px; height:21px\9;#height:18px;border:1px solid #556;" onfocus="this.select()">
<input type="hidden" name="idValue" id="idValue">
</div>
</body>
</html>
一
二
三
我想发布添加的值,以便将其包含在下一轮的下拉列表中。我建议您使用
jQuery
,以便于实现。您可以将它们包装在表单中
,并通过jQuery Ajax
执行POST
ing,然后将该值存储在某个地方供将来使用,然后将其作为新的选项
项附加到下一个项目中
通过aJax发布
$(function() {
$('#form').on('submit', function(e) {
// do not reload the page
e.preventDefault();
// do the posting
var newValue = $('#displayValue').val();
$.post('http://MYURL.com/post.php', {
new_field: newValue
}, function(data) {
// success callback
$('#form > select').append('<option value="'+newValue+'">'+newValue+'</option>');
})
});
})
$(函数(){
$('#form')。关于('submit',函数(e){
//不要重新加载页面
e、 预防默认值();
//发帖
var newValue=$('#displayValue').val();
$.post($)http://MYURL.com/post.php', {
新字段:newValue
},函数(数据){
//成功回调
$(“#表单>选择”).append(“”+newValue+“”);
})
});
})
基本上,您将newValue
发布到http://MYURL.com/post.php
并处理该新数据,然后success
回调将处理将新值插入您的select
代码没有经过测试,如果不起作用请告诉我
了解更多关于“组合框”的信息,如您试图创建的组合框在HTML中不受很好的支持。我建议您在下拉菜单中选择“其他”,并在其下方使用单独的文本框。