GVKun编程网logo

SwiftUI:如何在单击按钮时显示视图?(swiftui点击按钮跳转)

21

本文将带您了解关于SwiftUI:如何在单击按钮时显示视图?的新内容,同时我们还将为您解释swiftui点击按钮跳转的相关知识,另外,我们还将为您提供关于AJAX:如何在单击按钮时在客户端和服务器端更

本文将带您了解关于SwiftUI:如何在单击按钮时显示视图?的新内容,同时我们还将为您解释swiftui点击按钮跳转的相关知识,另外,我们还将为您提供关于AJAX:如何在单击按钮时在客户端和服务器端更改值?、BootstrapVue:如何在单击按钮时关闭弹出窗口/表单、css – 单击按钮时显示蓝色轮廓、javascript – 如何在单击“特定”按钮时显示特定值的实用信息。

本文目录一览:

SwiftUI:如何在单击按钮时显示视图?(swiftui点击按钮跳转)

SwiftUI:如何在单击按钮时显示视图?(swiftui点击按钮跳转)

我正在尝试使用Apple的 SwiftUI 制作一个应用程序,我需要有两个按钮在同一List行中显示两个不同的视图。

我使用 Xcode beta 7MacOS 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:如何在单击按钮时在客户端和服务器端更改值?

AJAX:如何在单击按钮时在客户端和服务器端更改值?

在以下SSCCE中,

  1. 我有一个字符串,其中包含3 div秒的HTML 。
  2. div除第一个之外的所有s 添加了一个属性。
  3. 我添加一个按钮,所有的div小号除了最后一个,并添加一个JS onclick事件侦听器,应该改变当前div‘样式属性s到(当前divid传递给JS功能属性),并在未来div的(这id是还传递给JS函数)样式属性
  4. submit在最后div提交一个按钮form。我没有为此按钮编写“ 事件actionform或“事件监听器” 的属性,因为现在这不是问题。
  5. 我打印div的。

问题:

currentIdnextId传递到按钮点击事件的JS事件监听器是在一个名为函数计算returnCurrentId它接受
$array_of_divs$array_of_ids作为参数。然后,它检查div具有的并将其设置为current_id。然后,旁边的ID将$array_of_ids成为中的ID
next_id

当JS更改了divs 的样式属性,该s的ids
属性已在客户端传递给它,而在服务器端没有任何变化时,就会出现问题。因此,在服务器端,无需更改显示属性就可以将$array_of_ids其传递给它returnCurrentId,因此返回id与第一个和第二个相同的div。它们被传递给JS,然后再次div显示相同的内容。

我的努力:

所以我一直在AJAX读了这里,我试图发送一个名为变量pass_backURLXMLHTTPRequest.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:如何在单击按钮时关闭弹出窗口/表单

BootstrapVue:如何在单击按钮时关闭弹出窗口/表单

  1. ref 元素上设置 b-modal
  2. 点击“确定”按钮,调用函数 hideModal
  3. 最后使用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>

css – 单击按钮时显示蓝色轮廓

css – 单击按钮时显示蓝色轮廓

我添加了这个,但仍然蓝色的轮廓出现时,按钮被点击。
.btn:focus {
  outline: none;
}

如何清除丑陋的东西?

解决方法

可能是你的属性正在被覆盖。
尝试附加!对您的代码重要,以及:活动。
.btn:focus,.btn:active {
   outline: none !important;
}

javascript – 如何在单击“特定”按钮时显示特定值

javascript – 如何在单击“特定”按钮时显示特定值

当我点击所有按钮输出将是相同的(即1).我想显示指定按钮的具体值为例子: – 当我点击按钮1然后它必须显示输出为1,当我点击2它必须显示输出为请帮助我.

enter image description here

<?PHP
    for ($i=0; $i < 10 ; $i++) { 
    echo '<br><button value="'.$i.'">'.$i.'</button>';
 }
?>

<script type="text/javascript">

    $('.my_remark_btn').click(function(){
        remark_aftr_click();  
    });

     function remark_aftr_click(){
        var k = $(".my_remark_btn").val();  
         $.ajax({url: "my_remark_act.PHP",
             cache: true,
             type: "POST",
             data: {go:k},
            success: function(data_remark_mi){
                alert(data_remark_mi);
           }
         });
      }

</script>

my_remark_act.PHP: –

<?PHP echo $_POST['go']; ?>

解决方法:

你需要$(this).attr(“value”),如下所示: –

<script type="text/javascript">
    $('.my_remark_btn').click(function(){
        var k = $(this).attr("value");
        $.ajax({url: "my_remark_act.PHP",
             cache: true,
             type: "POST",
             data: {go:k},
            success: function(data_remark_mi){
                alert(data_remark_mi);
            }
         });
     });
</script>

例:-

$('.my_remark_btn').click(function(){
  var k = $(this).attr("value");
  alert(k);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button value ="1">1</button><br>
<button value ="2">2</button>

今天关于SwiftUI:如何在单击按钮时显示视图?swiftui点击按钮跳转的讲解已经结束,谢谢您的阅读,如果想了解更多关于AJAX:如何在单击按钮时在客户端和服务器端更改值?、BootstrapVue:如何在单击按钮时关闭弹出窗口/表单、css – 单击按钮时显示蓝色轮廓、javascript – 如何在单击“特定”按钮时显示特定值的相关知识,请在本站搜索。

本文标签:

上一篇带有XIB Swift的UITableViewCell子类(swiftui 列表)

下一篇为什么在Swift中初始化变量的行上出现“初始化前使用变量”错误?