English 中文(简体)
如何在营地内一个纽州对一人进行安抚?
原标题:How to substring one by one in one button in php?
  • 时间:2011-05-17 01:54:12
  •  标签:
  • php

How to substring one by one in one button in php ? Example: $myvar="abc"; i need one button when click 1 time=display a, click 2time display b, and click 3time display c. click how many time ?depend on string of $myvar.

最佳做法

问题回答

你们应当研究这一ir。

不管怎么说,如果假设纽芬兰语为“Btn”的话,那就给你一些代码;

var str =  abc ;
var n = 0;
var btn = document.getElementById( Btn );

btn.onclick = function() {
    alert(str.substring(n, n + 1));
    n = (n + 1) % 3;
};

Oh, i made a mistake. the semicolon at the end of "n = (n + 1) % 3" is not correct!(i carelessly used a chinese semicolon instead...)

var str =  abc ;
var n = 0;
var btn = document.getElementById( Btn );

btn.onclick = function() {
    alert(str.substring(n, n + 1));
    n = (n + 1) % 3;
};

这可能是科索沃。

i 假定你用来显示的成分为“Txt”,可以是“span”或“div”或你喜欢的任何其他内容。

<a href="#" id="Btn">Click Me!</a>
<span id="Txt"></span>

---------------------------------------------------------------------------------------
function displayOneByOne(str) {
    var n = 0;
    var btn = document.getElementById( Btn )    //get the clickable element
    var txt = document.getElementById( Txt )    //get the area to display the character

    btn.onclick = function() {
        txt.innerHTML = str.substring(n, n + 1);
------------------------------------------------
        if (n < str.length) n++;
        else return false;
------------------------------------------------
    }
}

displayOneByOne("YOUR_STRING_HERE");
---------------------------------------------------------------------------------------
<a href="#" id="Btn">Click Me!</a>
<span id="Txt"></span>

---------------------------------------------------------------------------------------
function displayOneByOne(str) {
    var n = 1;
    var btn = document.getElementById( Btn )    //get the clickable element
    var txt = document.getElementById( Txt )    //get the area to display the character

    btn.onclick = function() {
        if (n <= str.length)
        txt.innerHTML = str.substring(0, n++);
        return false;
    }
}

displayOneByOne("YOUR_OWN_STRING");
--------------------------------------------------------------------------------------

如果你在点击“abc”的话,就会显示:

“a” ->





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签