coin-change 相关问题


修复`缺少冻结字符串文字注释`问题

我创建了一个新的迁移,它看起来像这样: 类 AddCommentsToUsers < ActiveRecord::Migration def change add_column :users, :comments, :text end end Now with Code Climate I am ...


在 Ruby On Rails 中出现“堆栈级别太深错误”

当我在index.html.erb中调用vendor.account_owner时,出现堆栈级别太深错误 供应商迁移文件如下所示 创建供应商类 < ActiveRecord::Migration[7.0] def change...


反应子组件失去对Change的关注

我有一个父组件 MasterList,我需要打开一个模式弹出窗口,其中包含一个表单,用于根据 activeTab(名称或组织)有条件地添加名称和组织,因为我...


加密后我的 PDF 文本字段在 Chrome 和 Adobe Reader 中不可见,但在 Mozilla 和 X-Change Editor 中可见

我创建了一个有效的 pdf,其中包含一个空白页和一个现有文本字段,一切都很好: 我可以编辑pdf并保存它,一切都很好。我用验证工具测试了pdf,p...


jQuery Ajax 在 php 同一页面上传递值 - 更新

如何找回: 如何找回: <div id="test"> <?php if (isset($_POST['sweets'])) { ob_clean(); echo $_POST['sweets']; exit; } ?> </div> <form id="a" action="" method="post"> <select name="sweets" onchange="change()" id="select1"> <option >Chocolate</option> <option selected="selected">Candy</option> <option >Taffy</option> <option >Caramel</option> <option >Fudge</option> <option >Cookie</option> </select> </form> <!-- Script --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script> function change() { var sweets = $("#select1").val(); $.ajax({ type: "POST", data: { sweets: sweets }, success: function(data) { $("#test").html(data); } }); } </script> 将值传递给 php 字符串: $string = $_POST['sweets']; <!-- I'm looking for this: --> 我希望这是可能的。我在 stackoverflow 和 google 上寻找答案,但找不到适合我的目的的答案。 对于同一个页面的ajax/PHP脚本,可以将PHP放在脚本的最前面,当有POST提交数据时以exit结束 为了使其更有意义,您应该返回与您通过 POST 提交的内容相关的内容(这是甜食的类型),作为示例,我们展示其一般定义。我们可以使用 switch,这是用于此目的的常用结构: switch ($string) { case "Chocolate": echo "Chocolate is made from cocoa beans, the dried and fermented seeds of the cacao tree"; break; case "Candy": echo "Candy is a sweet food made from sugar or chocolate, or a piece of this"; break; case "Taffy": echo "Taffy is a type of candy invented in the United States, made by stretching and/or pulling a sticky mass of a soft candy base"; break; case "Caramel": echo "Caramel is made of sugar or syrup heated until it turns brown, used as a flavouring or colouring for food or drink"; break; case "Fudge": echo "Fudge is a dense, rich confection typically made with sugar, milk or cream, butter and chocolate or other flavorings"; break; case "Cookie": echo "A cookie (American English) or biscuit (British English) is a baked snack or dessert that is typically small, flat, and sweet"; break; } exit; } ?> 所以以下是示例代码: <?php if (isset($_POST['sweets'])) { // ob_clean(); $string = $_POST['sweets']; switch ($string) { case "Chocolate": echo "Chocolate is made from cocoa beans, the dried and fermented seeds of the cacao tree"; break; case "Candy": echo "Candy is a sweet food made from sugar or chocolate, or a piece of this"; break; case "Taffy": echo "Taffy is a type of candy invented in the United States, made by stretching and/or pulling a sticky mass of a soft candy base"; break; case "Caramel": echo "Caramel is made of sugar or syrup heated until it turns brown, used as a flavouring or colouring for food or drink"; break; case "Fudge": echo "Fudge is a dense, rich confection typically made with sugar, milk or cream, butter and chocolate or other flavorings"; break; case "Cookie": echo "A cookie (American English) or biscuit (British English) is a baked snack or dessert that is typically small, flat, and sweet"; break; } exit; } ?> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <select name="sweets" onchange="change()" id="select1"> <option value="">Please select</option> <option >Chocolate</option> <option >Candy</option> <option >Taffy</option> <option >Caramel</option> <option >Fudge</option> <option >Cookie</option> </select> <br><br> <div id="test"></div> <script> function change() { var sweets = $("#select1").val(); $.ajax({ type: "POST", data: { sweets: sweets }, success: function(data) { $("#test").html(data); } }); } </script>


从数据库表中选择选择选项后如何显示/隐藏隐藏的 Div?

以下是选择选项的代码: 这是选择选项的代码: <div class="modal-body row"> <form role="form" action="patient/addNew" class="clearfix" method="post" enctype="multipart/form-data"> <div class="form-group col-md-6"> <label for="exampleInputEmail1"><?php echo lang('categorie'); ?></label> <select class="form-control m-bot15" name="categorie" value='' id="p_category"> <option value="#"> Sélectionner catégorie</option> <?php foreach ($categories as $category) { ?> <option value="category"><?php if (!empty($setval)) { if ($category->category == set_value('category')) { echo 'selected'; } } if (!empty($patient->category)) { if ($category->category == $patient->category) { echo 'selected'; } } ?> > <?php echo $category->category; ?> </option> <?php } ?> </select> </div> 这是应该显示/隐藏的 Div: <div class="form-group col-md-6" id="divCacher" style="display: none"> <label for="exampleInputEmail1"><?php echo lang('name_husband'); ?></label> <input type="text" class="form-control" name="name_Us" id="nameUs" placeholder=""> <label for="exampleInputEmail1"><?php echo lang('number_pregnancy'); ?></label> <input type="number" class="form-control" name="number_pregnancy" id="nbreEnfants" placeholder=""> </div> 这是 JavaScript 代码: $(document).ready(function () { $('.divCacher').hide(); $(document.body).on('change', '#p_category', function () { var v = $("select.p_category option:selected").val() if (v == 'Fe_Ence') { $('.divCacher').show(); } else { $('.divCacher').hide(); } }); }); 我希望如果我们选择 Fe_Ence 类别,则 div 会显示,否则,它会保持隐藏 您需要将 $category 设置为选项值更改此: <option value="category"> 对此: <option value="<?=$category?>"> 以下是适用于更多此类情况的示例: <!--SELECT INPUT--> <select id="p_category"> <option value=""> Sélectionner catégorie</option> <?php foreach ($categories as $category): ?> <option value="<?=$category?>"><?=$category?> <?php endforeach;?> </select> <!--Container List--> <div class="cat-container" data-id="test1"> <h1>This is Test1 Category</h1> </div> <div class="cat-container" data-id="Fe_Ence"> <h1>This is Fe_Ence Category</h1> </div> <div class="cat-container" data-id="test3"> <h1>This is test3 Category</h1> </div> // Javascript code checkCategory(); $("#p_category").on('change', checkCategory) function checkCategory() { $('.cat-container').hide() const selected = $('#p_category').val() if (!selected) return; $(`[data-id=${selected}`).show() }


选中/取消选中 mat-checkbox 未正确返回 true 或 false

我正在使用 Angular 15 和 Angular Material 14,下面是我用来显示复选框列表的 HTML 代码 我正在 Angular 15 和 Angular Material 14 工作,下面是我用来显示复选框列表的 HTML 代码 <div *ngFor="let control of checkboxArray.controls;let i = index" > <mat-checkbox [formControl]="control" (input)="validateInputs(notificationForm)" [checked]="control.value" (change)="control.checked=$event.checked;onCheckedChange(i);"> {{ checkboxItems[i].name }} </mat-checkbox> </div> 下面是Angular中onCheckedChange函数的代码 onCheckedChange(index: number) { this.sortCheckboxArray(); const checkboxItem = this.checkboxItems[index]; const control = this.checkboxArray.at(index); if (control) { if (control.value) { this.lists.push(checkboxItem.id.toString()); } else { this.lists.pop(checkboxItem.id.toString()); } } this.updateSubscriberGroupsCount(); this.cdr.detectChanges(); } 当我选中复选框时,在这个 onCheckedChange 函数中,control.value 始终返回 false。哪里出了问题?无法理解.. 这是一个工作版本,复选框逻辑工作正常,希望有帮助! 我们需要使用control.value获取表单组,但我们还需要访问内部表单控件,然后获取复选框值! import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { FormArray, FormControl, FormGroup, ReactiveFormsModule, } from '@angular/forms'; import { bootstrapApplication } from '@angular/platform-browser'; import 'zone.js'; import { MatCheckboxModule } from '@angular/material/checkbox'; @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule], template: ` <form [formGroup]="form"> <div formArrayName="array"> <div *ngFor="let control of checkboxArray.controls;let i = index" [formGroupName]="i"> <mat-checkbox formControlName="test" style="margin-bottom: 15px;" (change)="onCheckedChange(i);"> {{ checkboxItems[i].name }} </mat-checkbox> </div> </div> </form> `, }) export class App { name = 'Angular'; form = new FormGroup({ array: new FormArray([]), }); lists = []; checkboxItems: any = []; ngOnInit() { this.add(); this.add(); this.add(); } add() { this.checkboxArray.push( new FormGroup({ test: new FormControl(false), }) ); this.checkboxItems.push({ name: 'test' }); } get checkboxArray() { return this.form.get('array') as FormArray; } onCheckedChange(index: number) { // this.sortCheckboxArray(); // const checkboxItem = this.checkboxItems[index]; const control = this.checkboxArray.at(index); if (control) { if (control.value.test) { console.log('checked'); // this.lists.push(checkboxItem.id.toString()); } else { console.log('not checked'); // this.lists.pop(checkboxItem.id.toString()); } } // this.updateSubscriberGroupsCount(); // this.cdr.detectChanges(); } } bootstrapApplication(App); 堆栈闪电战


观察子组件中的@Output事件发射器?

应该如何在子组件中使用/观察父 @Output() 事件发射器? 例如,在此演示中,子组件使用 @Output onGreetingChange,如下所示: 应该如何在子组件中使用/观察父级@Output()事件发射器? 例如在这个演示中子组件使用@Output onGreetingChange,如下所示: <app-greeting [greeting]="onGreetingChange | async"></app-greeting> 如果 onGreetingChange 在 AfterViewInit 生命周期钩子中发出,这将起作用。 ngAfterViewInit() { this.onGreetingChange.emit('Hola'); } 但是这会产生 ExpressionChangedAfterItHasBeenCheckedError 错误。 有没有办法让它工作而不产生错误? 我尝试在 constructor 和 OnInit 中发射。想法? 您可以使用 change detection 手动触发 detectChanges() ngAfterViewInit() { this.onGreetingChange.emit('Hola'); this.cdr.detectChanges(); } 堆栈闪电战


链接到管理模板中的不同管理对象

我不想让js弄脏我的手。我有两个模型,汽车和模型。 如何在自定义管理模板中手动添加从汽车到其模型的链接? 我可以: 我不想让 js 弄脏我的手。我有两个型号,car和model。 如何在自定义管理模板中手动添加从汽车到其模型的链接? 我能做到: <a href="{% url 'admin:appname_carmodels_changelist' %}">access changelist</a> 但是我如何访问 pk=42 的模型呢?我试过: <a href="{% url 'admin:appname_carmodels_change' 42 %}">access changeform</a> 但我最终得到了NoReverseMatch at /admin/appname/carmodel/.../change/。这可能吗?还是我必须使用一些可以携带反向功能的extra_context? from django.urls import reverse from django.utils.html import format_html @admin.register(YourAPP) class AdminCustome(admin.ModelAdmin): list_display = ('id', 'link_to_other_obj',) def link_to_other_obj(self, obj): # foreign key is your other object(for example carmodel) related_obj = obj.foreign_key url = reverse('admin:appname_carmodels_change', args=[related_obj.id]) return format_html('<a href="{}">{}</a>', url, related_obj) link_to_other_obj.short_description = 'go_to_car_model_page'


如何使用 Javascript 单击按钮来获取按钮内的文本?

我需要 html 段落中的结果 这里是按钮文本 这是Html部分 我需要这个文本... 我需要 html 段落中的结果 <p id="result">Here the Button Text</p> 这是Html部分 <button type="button" id="vteam">i need this text</button> 这是JS部分 $(document).on('click', '.vteam', function(event) {} event.target指的是单击的元素,因此您可以像这样获取其中的文本:event.target.innerText。 我认为你可以使用以下内容: function changeText() { document.getElementById("vteam").innerHTML = "Hello"; } 和 <p id="vteam" onclick="changeText()">I need this text to change</p> 嘿我最近找到了解决这个问题的简单方法: 您可以将内部文本作为元素的 id 提供。在事件处理程序中,您可以通过以下方式访问内部文本: e.目标.id 希望这个解决方案可以帮助您:)


从数据库中选择 SELECT 选项后如何显示/隐藏 DIV?

这是选择选项的代码; 这是选择选项的代码; <div class="modal-body row"> <form role="form" action="patient/addNew" class="clearfix" method="post" enctype="multipart/form-data"> <div class="form-group col-md-6"> <label for="exampleInputEmail1"><?php echo lang('categorie'); ?></label> <select class="form-control m-bot15" name="categorie" value='' id="p_category"> <option value="#"> Sélectionner catégorie</option> <?php foreach ($categories as $category) { ?> <option value="category"><?php if (!empty($setval)) { if ($category->category == set_value('category')) { echo 'selected'; } } if (!empty($patient->category)) { if ($category->category == $patient->category) { echo 'selected'; } } ?> > <?php echo $category->category; ?> </option> <?php } ?> </select> </div> 这是必须显示/隐藏的 div: <label for="exampleInputEmail1"><?php echo lang('name_Us'); ?></label> <input type="text" class="form-control" name="name_husband" id="nameUs" placeholder=""> <label for="exampleInputEmail1"><?php echo lang('number_pre'); ?></label> <input type="number" class="form-control" name="number_pre" id="nbreEnf" placeholder=""> </div> 这是 JavaScript 代码: $('.divUs').hide(); $(document.body).on('change', '#p_category', function () { var v = $("select.p_category option:selected").val() if (v == 'Fe_Ence') { $('.divUs').show(); } else { $('.divUs').hide(); } }); }); 我希望如果选择了元素(Fe_Ence),则可以显示 div,否则,它保持隐藏 例如,您可以使用 :has 选择器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="thingtohide"> <h1>Hello</h1> </div> <div id="checkbox"> <input type="checkbox"> </div> <style> body:has(#checkbox input:checked) #thingtohide { visibility: hidden; } </style> </body> </html> 因此,如果父元素有一个选中的复选框,那么您可以定位与该父元素不同的子元素。


Jquery 使用 varA varB varC 在 <textarea> 中输入文本

我不知道如何在 Jquery 中编码: 我住在varA varB VarC 文本:我住在:通过输入输入文本 varC :将从 select 中获取,例如: 我不知道如何在 Jquery 中编写代码: <textarea>I am living in varA varB VarC</textarea> 文本:我住在:通过输入输入文本 varC :将从 select 中获取,例如: <select name="city" id="city"> <option value="1">City1</option> <option value="2">City2</option> </select> 当客户选择选择城市时,varC 将显示 City1 或 City2,但当他们重新选择时,varC 也会相应更改。所选地区和病房的 varA 和 varB <select name="district" id="district"> <option value="1">District1</option> <option value="2">District</option> </select> <select name="ward" id="ward"> <option value="1">Ward1</option> <option value="2">Ward</option> </select> 感谢您对我的帮助! 你可以做类似的事情。正如人们所说,Stackoverflow 社区并不是为你编写代码。雇用一名开发人员... $('select').on('change',function(){ let district = $('#district').val() let ward = $('#ward').val() let city = $('#city').val() $('textarea').val('I am living in '+district+' '+ward+' '+city) }) <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select name="district" id="district"> <option value="District1">District1</option> <option value="District">District</option> </select> <select name="ward" id="ward"> <option value="Ward1">Ward1</option> <option value="Ward">Ward</option> </select> <select name="city" id="city"> <option value="City1">City1</option> <option value="City2">City2</option> </select> <textarea>I am living in varA varB VarC</textarea>


如何使用预选值初始化下拉列表(<select/>)然后更改它?

我有一个网格,每行都有下拉菜单,我需要从数据库渲染它的状态。 因此,我定义了与指定用于从数据库中预选择值的选定选项类似的下拉菜单。 我有一个网格,每一行都有下拉菜单,我需要从数据库渲染它的状态。 因此,我定义了下拉列表,并指定了用于从数据库中预选择值的选定选项。 <select id='selectId'> <option value='1'>Option 1</option> <option value='2' selected='selected'>Option 2</option> <option value='3'>Option 3</option> </select>​ 问题在于,当我更改浏览器中定义的下拉列表的值时,它会在 UI 上发生变化,但选定的属性不会移动并保持在原来的位置。 因此,当我调用 $("#selectId").val() 时,我会得到旧的值。 初始化下拉控件然后能够在浏览器中或通过 jQuery 自由更改其值的适当方法是什么? 这似乎工作正常(Ubuntu 上的 Firefox): HTML <select id='selectId'> <option value='1'>Option 1</option> <option value='2' selected='selected'>Option 2</option> <option value='3'>Option 3</option> </select> JS $('#selectId').change(function() { var opt = $(this).find('option:selected'); console.log([opt.val(), opt.text()]); }); var opt_sel = $('#selectId option:selected'); opt_sel.val(99); opt_sel.text('Changed option'); 如果您选择这些选项,您将看到它将打印更改后的版本。工作示例: http://jsfiddle.net/vm4Q8/ 希望这有帮助。 应该可以正常工作。可能是你设置不正确。 您应该将选项的 value 传递给 val() 方法来选择它。 例如 $('#selectId').val('1'); 会将第一个选项设置为选定状态,然后调用 $('#selectId').val() 将为您提供 1 而不是 2。 这是工作示例http://jsfiddle.net/3eu85/ 可以获取选中选项的val,而不是select $('select#selectId option:selected').val(); 文档:http://api.jquery.com/val/ 您在哪个浏览器中尝试此操作?你的代码对我来说看起来很好,并且似乎可以在 this jsFiddle 中工作。 请使用此代码, $('#selectId option:selected').val(); <script> $(document).ready(function () { $('#ta_ingredient').val('2'); }); </script>


具有多个值的JS var

有件事我无法理解: 我有一个打开同一页面的功能,但具有不同的内容,具体取决于菜单中单击的按钮: 有件事我无法理解: 我有一个打开同一页面的功能<div id="page">但具有不同的内容,具体取决于菜单中单击的按钮: <nav> <button onclick="openPage(1)">PAGE 1</button> <button onclick="openPage(2)">PAGE 2</button> <button onclick="openPage(3)">PAGE 3</button> </nav> 然后是函数: function openPage(p){ var move=0; // define a var for USER action if(p==1){ document.getElementById('page').innerHTML = text_1; // content preloaded } else if(p==2){ document.getElementById('page').innerHTML = text_2; } else if(p==3){ document.getElementById('page').innerHTML = text_3; } // then on the top of the page (absolute + z-index) I add a HTML object: document.getElementById('page').innerHTML += '<aside id="pictures">content</aside>'; // what I'm now trying to do is to remove this object once USER move its mouse on it document.getElementById('pictures').addEventListener("mousemove",function(event) { setTimeout(function(){ move+=1; // increase the val each second },1e3) console.log('move'+p+' = '+move) // control value if(move>100){ document.getElementById('pictures').style.display = "none"; // OK, it works move=0; // reinit the var } }); } 现在惊喜: 第 1 页的控制台 move1 = 0 move1 = 1 ... move1 = 99 move1 = 100 // 'pictures' disappears 第 2 页的控制台 move1 = 41 move2 = 0 ... move1 = 58 move1 = 17 ... move1 = 100 // 'pictures' disappears move2 = 59 第 3 页的控制台 move1 = 15 move2 = 88 move3 = 0 ... move1 = 37 move2 = 100 // 'pictures' disappears move3 = 12 ... 我的 var 'move' 同时获得 3 个值...这怎么可能? 您的问题的原因是您每次调用 openPage 函数时都会添加一个事件侦听器。这意味着,如果您单击多个按钮,每个按钮都会有自己的事件侦听器附加到 #pictures 元素。现在,当触发 mousemove 事件时,所有这些侦听器将同时执行,导致 move 变量每秒递增多次。 解决此问题的方法是在添加新事件侦听器之前先删除现有的事件侦听器。 let handler; // to hold the event listener function const pictureEl = document.getElementById('pictures'); function openPage(p){ // Remove existing event listener if (handler) { // <-- Check here pictureEl.removeEventListener("mousemove", handler); } handler = function(event) { // ...Rest } }; // Add new event listener pictureEl.addEventListener("mousemove", handler); // ...rest 找到了另一种(最简单的?)方法: var move=0; // placed out of functions function openPage(p){ .... (same as previous) getElementById('pictures').addEventListener("mousemove",outPicts); // change } // put mousemove event in another function: function outPicts(p){ setTimeout(function(){ move+=1; },1e3) console.log('move = '+move) if(move>100){ document.getElementById('pictures').style.display = "none"; // then remove event getElementById('pictures').removeEventListener("mousemove",outPicts); move=0; // reinit the var } } 按预期工作


显示输入类型日期的占位符文本

占位符不适用于直接输入类型日期和日期时间本地。 占位符不适用于直接输入类型 date 和 datetime-local。 <input type="date" placeholder="Date" /> <input type="datetime-local" placeholder="Date" /> 该字段在桌面上显示 mm/dd/yyy,而在移动设备上则不显示任何内容。 如何显示 Date 占位符文本? 使用onfocus="(this.type='date')",例如: <input required="" type="text" class="form-control" placeholder="Date" onfocus="(this.type='date')"/> 使用onfocus和onblur...这是一个例子: <input type="text" placeholder="Birth Date" onfocus="(this.type='date')" onblur="if(this.value==''){this.type='text'}"> 在这里,我尝试了 data 元素中的 input 属性。并使用 CSS 应用所需的占位符 <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> input[type="date"]::before { content: attr(data-placeholder); width: 100%; } /* hide our custom/fake placeholder text when in focus to show the default * 'mm/dd/yyyy' value and when valid to show the users' date of birth value. */ input[type="date"]:focus::before, input[type="date"]:valid::before { display: none } <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> 希望这有帮助 <input type="text" placeholder="*To Date" onfocus="(this.type='date')" onblur="(this.type='text')" > 这段代码对我有用。只需使用这个即可 对于 Angular 2,你可以使用这个指令 import {Directive, ElementRef, HostListener} from '@angular/core'; @Directive({ selector: '[appDateClick]' }) export class DateClickDirective { @HostListener('focus') onMouseFocus() { this.el.nativeElement.type = 'date'; setTimeout(()=>{this.el.nativeElement.click()},2); } @HostListener('blur') onMouseBlur() { if(this.el.nativeElement.value == ""){ this.el.nativeElement.type = 'text'; } } constructor(private el:ElementRef) { } } 并像下面一样使用它。 <input appDateClick name="targetDate" placeholder="buton name" type="text"> 对于 React,你可以这样做。 const onDateFocus = (e) => (e.target.type = "datetime-local"); const onDateBlur = (e) => (e.target.type = "text"); . . . <input onFocus={onDateFocus} onBlur={onDateBlur} type="text" placeholder="Event Date" /> 我是这样做的: var dateInputs = document.querySelectorAll('input[type="date"]'); dateInputs.forEach(function(input) { input.addEventListener('change', function() { input.classList.add('no-placeholder') }); }); input[type="date"] { position: relative; } input[type="date"]:not(.has-value):before { position: absolute; left: 10px; top: 30%; color: gray; background: var(--primary-light); content: attr(placeholder); } .no-placeholder:before{ content:''!important; } <input type="date" name="my-date" id="my-date" placeholder="My Date"> 现代浏览器使用 Shadow DOM 来方便输入日期和日期时间。因此,除非浏览器出于某种原因选择回退到 text 输入,否则不会显示占位符文本。您可以使用以下逻辑来适应这两种情况: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 我使用了 Tailwind CSS 语法,因为它很容易理解。让我们一点一点地分解它: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } 使用其 Shadow DOM 伪元素选择器隐藏本机选择器图标(通常是日历)。 input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } 选择所有未显示占位符的 date 和 datetime-local 输入,并且: 默认使用 placeholder 伪元素显示输入 ::before 文本 在小屏幕及以上屏幕上切换为使用 ::after 伪元素 input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 设置 ::before 和 ::after 伪元素的样式。


© www.soinside.com 2019 - 2024. All rights reserved.