jQuery动态生成的按钮没有CSS [英] Jquery Dynamically generated buttons no css
问题描述
我正在从Google Places Api中获取一些数据,我正在使用jquerymobile向用户显示最近的位置,数据来自JSON,我想生成一组按钮,以便用户轻松点击所选位置.>
已生成数据,但该按钮显示为没有样式的链接,甚至与具有样式的另一个按钮的代码相同.这是代码段.
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
}); //each
返回数据,但是没有Button样式..我的想法是,我将放置一个onclick()来设置一些值,并使用JQM样式设置按钮列表.
谢谢.
诺曼
您需要刷新页面,尝试执行以下操作:
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>').page();
} //endif
});
或者也许:
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
});
$('#dPlaces').page();
更新:
$('div').live('pageshow',function(event, ui){
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
});
$('#dPlaces').page();
});
文档: http://jquerymobile.com/demos/1.0a4.1/#docs/api/events.html
I am fetching some data from a Google Places Api, I am using jquerymobile to show a user nearest places, the data comes in JSON I want to generate a set of buttons so is easy for user to click selected location.
The data is generated but the button is showed as a link with no style, even is the same code of another button with style. here is the code snippet.
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
}); //each
Data is returned but no Button style.. the idea is I will put a onclick() to set some value and way a list of buttons but with JQM style.
thanks.
Norman
You need to refresh the page, try something like this:
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>').page();
} //endif
});
or maybe:
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
});
$('#dPlaces').page();
UPDATE:
$('div').live('pageshow',function(event, ui){
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
});
$('#dPlaces').page();
});
Docs: http://jquerymobile.com/demos/1.0a4.1/#docs/api/events.html
这篇关于jQuery动态生成的按钮没有CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!