本文将带您了解关于SwiftUI:如何在单击按钮时显示视图?的新内容,同时我们还将为您解释swiftui点击按钮跳转的相关知识,另外,我们还将为您提供关于AJAX:如何在单击按钮时在客户端和服务器端更
本文将带您了解关于SwiftUI:如何在单击按钮时显示视图?的新内容,同时我们还将为您解释swiftui点击按钮跳转的相关知识,另外,我们还将为您提供关于AJAX:如何在单击按钮时在客户端和服务器端更改值?、BootstrapVue:如何在单击按钮时关闭弹出窗口/表单、css – 单击按钮时显示蓝色轮廓、javascript – 如何在单击“特定”按钮时显示特定值的实用信息。
本文目录一览:- SwiftUI:如何在单击按钮时显示视图?(swiftui点击按钮跳转)
- AJAX:如何在单击按钮时在客户端和服务器端更改值?
- BootstrapVue:如何在单击按钮时关闭弹出窗口/表单
- css – 单击按钮时显示蓝色轮廓
- javascript – 如何在单击“特定”按钮时显示特定值
SwiftUI:如何在单击按钮时显示视图?(swiftui点击按钮跳转)
我正在尝试使用Apple的 SwiftUI 制作一个应用程序,我需要有两个按钮在同一List
行中显示两个不同的视图。
我使用 Xcode beta 7 和 MacOS Catalina beta 7
。我尝试添加一个Button
表示视图的视图,但是无法单击它,而当我尝试在Button
外部进行简单List
单击并单击该AddList()
视图时,该视图没有出现。我也尝试过添加一个navigationButton
内部,navigationButton
但是它也不起作用。tapAction
单击时也无法添加,视图仍然不会出现
NavigationView { List(0..<5) { item in NavigationLink(destination: ContentOfList()) { Text("hello") // dummy text Spacer() Text("edit") .tapAction { AddList() // This is the view I want to present } } }.navigationBarItems(trailing: NavigationLink(destination: AddList(), label: { // doesn''t work within navigationBarItems Image(systemName: "plus.circle.fill") })) }
我希望该AddList()
视图出现,但在两种情况下却不会。
答案1
小编典典改进版本(SwiftUI,iOS 13 beta 7)
消除由.sheet修饰符显示的模态的解决方案也相同。
import SwiftUIstruct DetailView: View { @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode> var body: some View { Button( "Here is Detail View. Tap to go back.", action: { self.presentationMode.wrappedValue.dismiss() } ) }}struct RootView: View { var body: some View { VStack { NavigationLink(destination: DetailView()) { Text("I am Root. Tap for Detail View.") } } }}struct ContentView: View { var body: some View { NavigationView { RootView() } }}
AJAX:如何在单击按钮时在客户端和服务器端更改值?
在以下SSCCE中,
- 我有一个字符串,其中包含3
div
秒的HTML 。 - 我
为
div
除第一个之外的所有s 添加了一个属性。 - 我添加一个按钮,所有的
div
小号除了最后一个,并添加一个JSonclick
事件侦听器,应该改变当前div
‘样式属性s到(当前
div
的id
传递给JS功能属性),并在未来div
的(这id
是还传递给JS函数)样式属性 - 我
submit
在最后div
提交一个按钮form
。我没有为此按钮编写“ 事件action
”form
或“事件监听器” 的属性,因为现在这不是问题。 - 我打印div的。
问题:
在currentId
和nextId
传递到按钮点击事件的JS事件监听器是在一个名为函数计算returnCurrentId
它接受
$array_of_divs
并$array_of_ids
作为参数。然后,它检查div
具有的并将其设置为
current_id
。然后,旁边的ID将$array_of_ids
成为中的ID
next_id
。
当JS更改了div
s 的样式属性,该s的id
s
属性已在客户端传递给它,而在服务器端没有任何变化时,就会出现问题。因此,在服务器端,无需更改显示属性就可以将$array_of_ids
其传递给它returnCurrentId
,因此返回id
与第一个和第二个相同的div
。它们被传递给JS,然后再次div
显示相同的内容。
我的努力:
所以我一直在AJAX读了这里,我试图发送一个名为变量pass_back
中URL
的XMLHTTPRequest.open(GET,URL,TRUE)
,并在服务器端,试图检查是否$ _REQUEST包含它,当它发生了,我做的风格同样变化属性,但似乎不包含它。
题:
我预计我会将代码块放在错误的位置,但是那我应该放在哪里。
那么谁能给我一些提示/建议/解决方案?
<?php
echo '<html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<script>
function clickButton(currentId,nextId) {
alert(currentId+","+nextId); //check
document.getElementById(currentId).style.display = "none";
document.getElementById(nextId).style.display = "block";
document.getElementById(nextId).style.border = "5px solid red";//check
//**************************
var xmlhttp;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.open("GET","C:/xampp/htdocs/testing.php?pass_back="+"pass_back",true);
xmlhttp.send();
//**************************
}
</script>
</head><body>';
//String of all the div's
$haystack = '<div id="div1">Div1</div>
<div id="div2">Div2</div>
<div id="div3">Div3</div>';
//Adding divs as DOM objects to an array
require 'C:\\xampp\\htdocs\\simple_html_dom.php';
$html = str_get_html($haystack);
foreach ($html->find('div') as $div) {
$array_of_divs[] = $div;
}
//Extract id attributes from all elements of $array_of_divs and add to $array_of_ids
foreach ($array_of_divs as $div) {
$array_of_ids[] = $div->id;
}
//Addproperty to all divs except the first one
for ($i=1; $i<count($array_of_divs); $i++) {
$array_of_divs[$i]->;
}
//Strings of the pseudo button to navigate to the next div on the same page and real button to navigate to another page
$pseudo_btn = '<button type="button" onClick="clickButton(\''.returnCurrentId($array_of_divs,$array_of_ids)['current_id'].'\',\''.returnCurrentId($array_of_divs,$array_of_ids)['next_id'].'\')">Submit</button>';
$real_btn = '<span><input type="submit" name="submit" value="Submit"></span>';
//Add $pseudo-btn to all except last div on this page,add $real_btn to the last div
$last_id = end($array_of_ids);
for ($j=0; $j<count($array_of_ids); $j++) {
if ($array_of_ids[$j] !== $last_id ) {
$array_of_divs[$j]->innertext .= $pseudo_btn;
} else {
$array_of_divs[$j]->innertext .= $real_btn;
}
}
//Print all the divs
echo '<form method="post" enctype="multipart/form-data" accept-charset="utf-8">';
foreach ($array_of_divs as $div) { echo $div; }
echo '</form>';
//**********************************************
//IF $_REQUEST CONTAINS pass_back (i.e. THE BUTTON HAS BEEN PRESSED,CHANGE DISPLAY PREPERTY OF CURRENT AND NEXT DIV
if (array_key_exists('pass_back',$_REQUEST)) {
foreach ($array_of_divs as $divs_el) {
if ( $divs_el->id == returnCurrentId($array_of_divs,$array_of_ids)[current_id] ) {
$divs_el->;
} else if ( $divs_el->id == returnCurrentId($array_of_divs,$array_of_ids)[next_id] ) {
$divs_el->;
}
}
} else {
echo '$_REQUEST does not contain pass_back';
}
//***********************************************
//This function returns the id of the current div which is displayed.
function returnCurrentId($array_of_divs,$array_of_ids) {
for ($c=0; $c<count($array_of_divs); $c++) {
$style_value = $array_of_divs[$c]->style;
$style_value = preg_replace('/\s+/','',$style_value);//This removes all kinds of white space.
if (strpos($style_value,'display:none') === false) {
$current_id= $array_of_divs[$c]->id;
break;
}
}
$current_position = array_search($current_id,$array_of_ids);
$next_id = $array_of_ids[$current_position + 1];
$array_to_pass= array('current_id'=>$current_id,'next_id'=>$next_id);
return $array_to_pass;
}
echo '</body></html>';
?>
BootstrapVue:如何在单击按钮时关闭弹出窗口/表单
- 在
ref
元素上设置b-modal
- 点击“确定”按钮,调用函数
hideModal
- 最后使用
this.$refs.modal1.hide();
关闭模态
new Vue({
el:"#app",data: () => ({ isRegisterFourth: true }),methods: {
hideModal() {
this.$refs.modal1.hide();
},resetNow() {}
}
});
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js"></script>
<script src="https://unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<div id="app">
<div>
<b-buttonv-on:click="resetNow"
v-b-modal.modal-1
>Register</b-button>
<b-modal ref="modal1" id="modal-1" title="">
<div>
<divv-if="isRegisterFourth">
<div>
<div/><div></div>
<div>
<button
type="button"@click="hideModal"
><b>OK!</b></button>
</div>
</div>
</div>
</div>
</b-modal>
</div>
</div>
default
中的 <b-modal>
槽公开了一个 hide
方法,您可以调用该方法来隐藏模态。您可以根据需要使用范围内的各种其他方法。您可以在 docs
new Vue({
el: "#app"
});
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap@4.5.3/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.min.css" />
<script src="https://unpkg.com/vue@2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.min.js"></script>
<div id="app">
<b-button v-b-modal.modal-1>Register</b-button>
<b-modal id="modal-1">
<template #default="{ hide }">
<b-button @click="hide">
Close Modal
</b-button>
</template>
</b-modal>
</div>