簡體   English   中英

刷新 <div id=“RefhreshableDiv”> 內容點擊按鈕

[英]Refresh <div id=“RefhreshableDiv”> content on button click

讓我直接說清楚。
在我網站的某個地方,我有以下代碼:

<?php  
echo '<div id="RefreshableDiv">';
/* performs changes to database,
   depending on whether button1 was clicked or not 
   with the help of: if (isset($_POST['button1'])) */

/* retrieves information from database */   

/* creates a button with id="button1", with background image 
   depending on retrieved database information */

echo '</div>';
?>

我正在嘗試為我的網站提供以下功能:

  • 用戶單擊button1
  • 只有<div>id "RefreshableDiv"的頁面部分才被刷新(結果button1背景圖像發生了變化。)

我正在嘗試做的甚至有可能嗎? 我認為我期望使用ajax。

好的,首先要有一個頁面,其中有數據庫更改和您需要的東西,並將其命名為: pagerefrech.php以免說出它的代碼如下:

<?php 
//selecting fr database and doing what do you want to do
//this page will return whats gonna be inside the div
//to get the parameter sent by $.post you use $_POST['nameofparam']
//exemple : 
  echo "THIS IS THE CONTENT OF THE DIV";
?>

並且您的按鈕cilck事件是:

$('#button').click(function(){
    $.post(//or $.get if you want to use GET request
    "pagerefrech.php",//path to teh page
    {
    param1  : value1 ,
    param2 : value2//for sending some post vars if you dont want to set it to null
    },
    function(data){//data contains the contenet returned by the page "pagerefrech.php"
    $('#RefreshableDiv').html(data);
    //change here the background image of the button
    $('#button1').css({"background-image" : "yourvaluegoeshere"});
    });//end of $.post function
});//end of button1.click

說明: $ .post發送POST請求到頁面pagerefrech.php獲得結果param1和param2和param3 .....是paramers,如果不可以,則可以添加它們以將它們發送到頁面,您可以將其設為{}里面沒有任何東西,這就像您要發送POST變量(例如輸入或選擇值)一樣。

簡單示例:使用以下代碼創建一個名為test.php的頁面:

<?php echo "cotent recieved"; ?>

使用此代碼創建一個html頁面

<html>
<head>
</head>
<body>
<input type="button" value="test" id="but1" />
<div id="refrech"></div>
<script>
$(document).ready(function(){
 $('#but1').click(function(){
        $.post(
        "test.php",
        {
        },
        function(data){
        $('#refrech').html(data);
        });
    });
});
</script>
</body>
</html>

PS:別忘了在測試中將jquery庫添加到頁面中,希望它很清楚

如何刷新<div>在 angular 中單擊按鈕內容更快?</div><div id="text_translate"><p> 我有一個具有一定價值的內容,單擊取消按鈕時,我需要刷新它並顯示新內容。 當我單擊取消按鈕時,舊內容會保留幾秒鍾,然后再更改為新內容。請告訴我如何更快地加載新內容而不會出現這種延遲。</p><pre> &lt;div&gt;Text&lt;/div&gt; &lt;button type="button" class="left-btn pull-right" (click)="reload()" data-dismiss="modal"&gt;cancel&lt;/button&gt; reload() { this.CommonService.GetDateTimeByTimeZone().subscribe(tz =&gt; { let ds: Input = { StartDate: moment(this.timezoneDate).format("YYYY-MM-DDT00:00:00.000[Z]"), EndDate: moment(this.timezoneDate).format("YYYY-MM-DDT23:59:59.999[Z]") } this.Dashboard(ds, false) }, error =&gt; { Swal.fire('', this.es.adminErrorMsgList[39].message, 'error') }); this.SelectedDate = ' '; }</pre></div>

[英]How to refresh <div> content faster on button click in angular?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM