我想检查一个字符串是否包含特殊字符,如!@#$%^&*.,<>/\'";;?并返回true,如果该字符串包含至少其中一个字符.
我尝试使用以下正则表达式脚本:
var format = /^[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/;
if( string.match(format) ){
return true;
}else{
return false;
}
Run Code Online (Sandbox Code Playgroud)
如果字符串仅包含特殊字符,则返回true,但如果字符串包含字母数字字符(!example1,.example2)等其他内容,则返回false.
我用php和javascript制作了一个幻灯片,它可以很好地滑动图像,但是我有点卡在后面和前面的功能上,如果你能在这里帮助我,我将不胜感激.这就是我所做的至今:
PHP:
$dir = 'images/slideshow';
$images = scandir($dir);
$i = 0;
echo '<div id="slideshow-wrapper">';
echo '<div id="slideshow-beta">';
foreach($images as $img){
if ($img != '.' && $img != '..') {
$i++;
echo '<img src="../images/slideshow/'.$img.'" class="img_'.$i.'">';
}
}
echo '</div>';
echo '<div id="slideshow-controller">';
echo '<div class="left-arrow-div"><span class="left-arrow" onclick="SlideShow(-1);"></span></div>';
echo '<div class="right-arrow-div"><span class="right-arrow" onclick="SlideShow(1);"></span></div>';
echo '</div>';
echo '</div>';
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var i=1;
var begin=true;
function SlideShow(x){
if(x==-1){
i--;
}else if(x==1){
i++;
}
var total=$('#slideshow-beta img').length;
for(var j=1;j<=total;j++){
if($('.img_'+j).css('display')!='none'){
begin=false;
break;
}else{
begin=true;
}
} …Run Code Online (Sandbox Code Playgroud) 我想构建一些媒体查询,以涵盖PC /笔记本电脑的大部分宽高比.
我的第一次尝试是这样的:
@media screen and (min-device-aspect-ratio: 4/3){
header::after{
content: '4/3';
}
}
@media screen and (min-device-aspect-ratio: 16/9){
header::after{
content: '16/9';
}
}
@media screen and (min-device-aspect-ratio: 16/10){
header::after{
content: '16/10';
}
}
Run Code Online (Sandbox Code Playgroud)
我正在测试那些分辨率为1366x768的笔记本电脑的查询,这是16/9的宽高比,而不是这个,执行16/10的最后一次查询.
我可以用经典的方式做到这一点,有:
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
Run Code Online (Sandbox Code Playgroud)
但我认为响应式设计应该更多地关注宽高比而不是屏幕宽度,因为它在4:3和16/9之间的差异很大,或者我可能误解了响应式设计概念,但这就是我的想法.
css aspect-ratio screen-resolution media-queries responsive-design
我尝试使用php gd创建验证码代码:
$im = imagecreatetruecolor(100, 25);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$imgstring=$_GET['captcha'];
$font = 'RAVIE.TTF';
imagettftext($im, 15, 0, 10, 20, $black, $font, $imgstring);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
Run Code Online (Sandbox Code Playgroud)
GET值与ajax一起发送,如下所示:
var randstring;
function Captcha() {
randstring = Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, 5))).toString(36).slice(1);
$.ajax({
url: 'test_image.php',
data: {'captcha' : randstring},
method: 'GET',
success: function (data){
console.log(data);
},
error: function (){
alert('Error');
return false;
}
});
} …Run Code Online (Sandbox Code Playgroud) 我有一个PHP脚本生成一个png图像,其中验证码为图像文本.
session_start();
$captchanumber = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
$captchanumber = substr(str_shuffle($captchanumber), 0, 8);
$_SESSION["code"] = $captchanumber;
$image = imagecreatefromjpeg("cap.jpg");
$black = imagecolorallocate($image, 160, 160, 160);
$font = '../assets/fonts/OpenSans-Regular.ttf';
imagettftext($image, 20, 0, 35, 27, $black, $font, $captchanumber);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
Run Code Online (Sandbox Code Playgroud)
我想通过jQuery或JavaScript重新加载图像,所以我使用这样的东西:
$(document).ready(function(e) {
$('.captcha').click(function(){
alert('yolo');
var id = Math.random();
$(".captcha").replaceWith('<img class="captcha" src="img/captcha.php?id='+id+'" />');
id ='';
});
});
Run Code Online (Sandbox Code Playgroud)
场:
<img class="captcha" src="img/captcha.php">
Run Code Online (Sandbox Code Playgroud)
作为第一次尝试,它的工作原理,但之后,如果我再次点击该字段,它将不再工作,我不知道为什么.
移动设备的垂直方向存在一个视口问题.正如您所看到的,在页脚下方,有一个填满屏幕的空白区域.如果我在水平方向上转动方向,则视口工作正常,对于平板电脑,桌面,等等.这个问题只存在于手机的垂直方向.有什么方法可以解决这个问题吗?
我已经有了这个元数据:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的"if"语句:
if( (first condition) || (second condition) || (third condition) ){
//line of code
}
Run Code Online (Sandbox Code Playgroud)
如果满足所有3个条件,我希望代码行运行3次.如果只满足2个条件,它必须运行2次,依此类推.
这个语法也很好:
if(){}elseif(){}elseif(){}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ajax 请求删除文件:
javascript:
function deleteFile(file_path)
{
var r = confirm("Sure?")
if(r == true)
{
$.ajax({
url: 'delete_file.php',
data: {'file' : file_path },
method: 'GET',
success: function (response) {
alert('Deleted!');
},
error: function () {
alert('Not Deleted!');
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
删除文件.php:
unlink($_GET['file']);
Run Code Online (Sandbox Code Playgroud)
成功则返回 true,但文件并未被删除。
我需要在用户离开路线并要求确认之前显示模式。基于该确认,用户可以离开路线。问题是确认作为一个承诺而来,并OnBeforeRouteLeave期望一个布尔值返回,而我无法在.then(). 我在他们的 API 上找不到任何内容,但是有我可以使用的方法吗?就像next()之前版本的 vue router 中的那样,或者可能是更适合这种情况的钩子?
onBeforeRouteLeave((to, from, next) => {
if(!isEqual(store.getters['product/getProduct'], initialState)) {
Swal.fire({
title: 'You want to leave the page?',
text: `There are unsaved changes that will be lost.`,
icon: 'warning',
showCancelButton: true,
buttonsStyling: false,
cancelButtonColor: '#d33',
confirmButtonColor: '#3085d6',
confirmButtonText: 'Yes, leave!',
customClass: {
confirmButton: "btn font-weight-bold btn-light-primary",
cancelButton: "btn font-weight-bold btn-light-primary",
},
heightAuto: false
}).then((result) => {
if (result.isConfirmed) {
store.commit('product/resetState')
next()
}
})
}
return false
})
Run Code Online (Sandbox Code Playgroud)
更新:
源代码上写着: …
如果它们的宽度超过容器宽度,我无法弄清楚如何保持多个div内联.如果所有div的宽度大约是1000 px而容器的宽度是500,我希望div与容器重叠,并且水平滚动酒吧出现.
#container {
overflow: hidden;
background: red;
width: 500px;
height: 500px;
}
#container>div {
border: 1px solid #000;
width: 30%;
height: 100px;
margin: 10px;
float: left;
}Run Code Online (Sandbox Code Playgroud)
<div id="container">
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
<div class="fourth"></div>
<br style="clear: both;">
</div>Run Code Online (Sandbox Code Playgroud)
小提琴:点击
javascript ×4
php ×4
css ×3
ajax ×2
html ×2
image ×2
jquery ×2
android ×1
aspect-ratio ×1
file ×1
mobile ×1
orientation ×1
php-gd ×1
regex ×1
slideshow ×1
string ×1
vue-router ×1
vue-router4 ×1
vuejs3 ×1