我现有代码的一小段。我将每个“显示” div的内容复制到“结果” div中。我有两个问题-首先,我必须单击两次单选按钮才能使其启动。其次,我要替换“结果” div的内容,而不是附加内容。我尝试了.html,但没有任何乐趣。
func validatePasscode(passcode: String,
successBlock: @escaping (Event?) -> Void,
failureBlock: @escaping (Error) -> Void)
{
let passcodeURL = URL (string: "\(PASSCODE_CHECKER_URL)/\(passcode)")
Alamofire.request(passcodeURL!, method: .get).responseJSON { (response) in
print(response)
if let error = response.error
{
failureBlock(error)
return
}
if let passcodeJSON = response.result.value as? [[String : Any]],
let passcodeObj = passcodeJSON.first {
print(passcodeObj)
let event = Event.init(JSON: passcodeObj);
successBlock(event)
}
}
}
答案 0 :(得分:0)
我想你想喜欢它:-
当您单击按钮时,这里有两个divs
和一个按钮,然后.div1
的内容被复制到.div2
$(document).ready(function(){
$('body').on('click', 'button', function(){
$('.loop').each(function(index, elem){
var div1Content = $(elem).find('.div1').html();
$(elem).find('.div2').html(div1Content);
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>replace content</button> <br><br>
<div class="loop">
<div class="div1">This is first div -- loop 1</div>
<div class="div2">this is second div -- loop 1</div>
</div>
<br>
<div class="loop">
<div class="div1">This is first div -- loop 2</div>
<div class="div2">this is second div -- loop 2</div>
</div>