谁能告诉我我的代码有什么问题,每当我通过我自己创建的分页导航到另一个页面并返回到上一个页面时,我已经单击了一个按钮(单击的按钮将有引导程序的btn-success和一个选中的图标),我单击的按钮将是默认的btn-primary。现在,当我在不同的页面中导航时,我想保持点击按钮的样式为btn-success。谢谢。
for(var isbnCount=0; isbnCount<isbnsplitted.length; isbnCount++){
if(value.ISBN==isbnsplitted[isbnCount]){
console.log("true: "+isbnsplitted[isbnCount]);
checkBox='<td id="buttons">'+
'<input type="hidden" id="'+value.ISBN+value.Title+'">'+
'<button type="button" class="button btn btn-success" name="'+value.ISBN+'" id="'+value.ISBN+'" value="'+value.Title+'"><i class="material-icons">check</i></button>'+
'</td>';
}
else{
console.log("false");
checkBox='<td id="buttons">'+
'<input type="hidden" id="'+value.ISBN+value.Title+'">'+
'<button type="button" class="button btn btn-primary" name="'+value.ISBN+'" id="'+value.ISBN+'" value="'+value.Title+'"><i class="material-icons">library_add</i></button>'+
'</td>';
}
}
}
bookCards='<tr id="tableRow">'+
'<td id="title">'+value.Title+'</td>'+
'<td id="author">'+value.Author+'</td>'+
'<td id="author">'+value.Category+'</td>'+
status+
checkBox+
'</tr>';
$('#tableBody').append(bookCards);
顺便说一下,我正在从我的服务器端加载一组新的数据,AJAX代码在这段代码之上。
发布于 2017-12-18 02:16:56
在这种情况下,我想推荐使用Redux (只是把它放在那里)。我现在已经在几个小应用程序上对JQuery和Redux进行了修补,它们在一起工作得非常好。
Redux可以存储用户的所有设置等,并消除了在jQuery函数中传递变量的复杂性。但更重要的是,与存储变量等相比,Redux存储可以很容易地持久化和重新加载。我有一个JsBin工作示例here,它存储和重新加载Redux存储。
// Reducer - takes the action types and reduces them into a new state condition.
const text = (state = {}, actions) =>{
switch (actions.type) {
case 'UPDATE_TEXT': return Object.assign({}, state, {value: actions.value})
default: return state
}
}
// Store to hold state of the app - only one store but many properties.
const updateText = Redux.createStore(text);
//Use subscribe() to update the UI in response to state changes.
updateText.subscribe(() => {
let text = updateText.getState().value
localStorage.setItem("text",text)
$('#display').text(text)
});
// The only way to mutate the internal state is to dispatch an action.
// Dispatch = "Please dispatch this change, please"
$('#square').on('keyup',(e) => updateText.dispatch({type:'UPDATE_TEXT','value':e.target.value}))
$(document).ready(()=>{
console.log('working')
let text = localStorage.getItem("text")
updateText.dispatch({type:'UPDATE_TEXT','value':text})
})
https://stackoverflow.com/questions/47857628
复制相似问题