如何从数据库中获取数据并在jquery中的selectbox中显示它 [英] how to fetch data from database and display it in selectbox in jquery
问题描述
< script type =text / javascript>
var arr = [{
val:1,
text: '选项1'
},{
val:2,
文字:'选项2'
} ];
$(function(){
$('a')。click(function(){
var sel = $( '< select>')。appendTo('body');
$(arr).each(function(){
sel.append($(< ;选项>)。val(this.val).text(this.text));
});
$('< br>')。 insertBefore(sel);
$('< input />')。insertAfter(sel);
返回false;
} );
});
< / script>
添加选择框
这个代码中的
,我在锚标签上显示选择框点击..如果我点击锚标签5次,那么它将打开5个选择框...没有到目前为止,选择框显示选项作为选项1和选项2作为给....而不是这些选项我想显示数据库中的数据...所以如何显示数据库中的数据...我想要获取来自表中的名称和id命名信息在数据库中,并希望在selectbox中显示名称和id作为选项值
数据库我使用的是sql和数据库名称是员工.. ..table名称是我想要获取的信息和表格字段是id和名称
任何人都可以在这方面帮助我....感谢提前
<script type="text/javascript">
var arr = [{
val: 1,
text: 'Option 1'
}, {
val: 2,
text: 'Option 2'
}];
$(function () {
$('a').click(function () {
var sel = $('<select>').appendTo('body');
$(arr).each(function () {
sel.append($("<option>").val(this.val).text(this.text));
});
$('<br>').insertBefore(sel);
$('<input/>').insertAfter(sel);
return false;
});
});
</script>
Add Select Box
here in this code, i am displaying selectboxes on anchor tag click..if i click on anchor tag 5 times then it will open 5 selectboxes...now till now the selectboxes are showing options as option 1 and option 2 as give....but instead of these options i want to display data from database...so how can i display data from database...i want to fetch name and id from table named information in database and want to display name in selectbox and id as option value
database i am using is sql and database name is employees....table name is information and table fields that i want to fetch are id and name
can anyone help me in this regard....thanks in advance
推荐答案
(function(){
(function () {
('a')。click(function(){
var sel =
('a').click(function () {
var sel =
('< select>')。appendTo('body');
('<select>').appendTo('body');
这篇关于如何从数据库中获取数据并在jquery中的selectbox中显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!